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
So, we should be ready that some projects will use the new style. However, this thing should be consistent across the project or at least in one context. In other words, let's forbid mixing list and List in one context.
The same for Dict, type, and so on. See PEP 585 for the full list.
Reasoning
Consistency about what style should be used.
For the older Python versions, there is not much choice what you can use for parametrized generics, so in some cases, the rule will advise you to use typing module even for unparametrized generics. While it sounds like one more import, asking users to do that import helps to avoid cases when the generic wasn't parametrized not because of complex annotation but because of lazyness.
The text was updated successfully, but these errors were encountered:
I think it is ok to have the rule to check only names, like if name in ('typing.List', 'List'). It looks like a good assumption that users have no their own List class or typing module. Otherwise, it would lead to conflicts with typing module anyway, and conflicting with stdlib isn't good.
Rule request
Thesis
Python 3.9 introduces a new way to create generics which is great:
So, we should be ready that some projects will use the new style. However, this thing should be consistent across the project or at least in one context. In other words, let's forbid mixing
list
andList
in one context.Good:
Bad:
The same for
Dict
,type
, and so on. See PEP 585 for the full list.Reasoning
Consistency about what style should be used.
For the older Python versions, there is not much choice what you can use for parametrized generics, so in some cases, the rule will advise you to use
typing
module even for unparametrized generics. While it sounds like one more import, asking users to do that import helps to avoid cases when the generic wasn't parametrized not because of complex annotation but because of lazyness.The text was updated successfully, but these errors were encountered: