Skip to content

RuleFactories have incorrect type annotations #2183

@jkhsjdhjs

Description

@jkhsjdhjs

The __init__() functions of most RuleFactories in routing.py have incorrect type annotations. The classes in question are Subdomain, Submount, EndpointPrefix and RuleTemplateFactory. All respective __init__() methods have the type of their rules parameter declared as Iterable[Rule], when it should be Iterable[RuleFactory].

I noticed this when upgrading werkzeug to 2.0.0 as this update introduced type annotations. My Map contains several Submounts which in turn contain other Submounts, which works perfectly fine. The new type annotations, however, don't allow this as Submounts aren't Rules:

aas/adapter/http.py:334: error: List item 0 has incompatible type "Submount"; expected "Rule"

Why I believe these type annotations are incorrect:

The get_rules() method of these RuleFactories contains the following loop:

for rulefactory in self.rules:

The naming here makes it pretty clear to me that self.rules (which is assigned directly from the rules parameter of the __init__() method) contains rule factories and not just rules. Also there would be no usecase for a get_rules() function if self.rules already only contained rules.
This and the fact that my code, in which I use nested RuleFactories, works, lead me to believe that the type annotation here are indeed wrong.

If confirmed, I'd be happy to provide a PR to fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions