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.
The
__init__()functions of most RuleFactories inrouting.pyhave incorrect type annotations. The classes in question areSubdomain,Submount,EndpointPrefixandRuleTemplateFactory. All respective__init__()methods have the type of theirrulesparameter declared asIterable[Rule], when it should beIterable[RuleFactory].I noticed this when upgrading werkzeug to 2.0.0 as this update introduced type annotations. My
Mapcontains severalSubmountswhich in turn contain otherSubmounts, which works perfectly fine. The new type annotations, however, don't allow this asSubmountsaren'tRules:Why I believe these type annotations are incorrect:
The
get_rules()method of theseRuleFactoriescontains the following loop:The naming here makes it pretty clear to me that
self.rules(which is assigned directly from therulesparameter of the__init__()method) contains rule factories and not just rules. Also there would be no usecase for aget_rules()function ifself.rulesalready 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.