You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
forrulefactoryinself.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 text was updated successfully, but these errors were encountered:
I believe I used Rule because that's the much more common case, and RuleFactory has other APIs that sort of make this type cascade. Can't really remember, but I recall it being less clear with the RuleFactory. PRs welcome though if you want to explore what it would look like.
I've opened #2185 in an attempt to fix this issue by simply changing the type annotations. This fixes the issue for my usecase of nested RuleFactories. I didn't fully understand what you meant with
RuleFactory has other APIs that sort of make this type cascade
The
__init__()
functions of most RuleFactories inrouting.py
have incorrect type annotations. The classes in question areSubdomain
,Submount
,EndpointPrefix
andRuleTemplateFactory
. All respective__init__()
methods have the type of theirrules
parameter 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
Map
contains severalSubmounts
which in turn contain otherSubmounts
, which works perfectly fine. The new type annotations, however, don't allow this asSubmounts
aren'tRules
:Why I believe these type annotations are incorrect:
The
get_rules()
method of theseRuleFactories
contains the following loop:The naming here makes it pretty clear to me that
self.rules
(which is assigned directly from therules
parameter of the__init__()
method) contains rule factories and not just rules. Also there would be no usecase for aget_rules()
function ifself.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 text was updated successfully, but these errors were encountered: