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
{{ message }}
Repository navigation
Inconsistencies between __init__ and __new__ #6905
I just implemented a new check in pyright called reportInconsistentConstructor that detects inconsistencies between the __init__ and __new__ methods. It's disabled by default but can be enabled in the configuration. It's in pyright 1.1.207, which I just published.
The check is pretty conservative, but it does identify three places in typeshed that look like legitimate problems.
The class WeakMethod in weakref.pyi defines a __new__ that is incompatible with the __init__ declared in its parent class ReferenceType.
The class _TokenType in pygments/token.pyi defines an __init__ that is incompatible with the __new__ in tuple[str].
The class CascadeOptions in SQLAlchemy/sqlalchemy/orm/util.pyi defines a __new__ that is incompatible with the __init__ in its parent class frozenset[Any].
If/when these are addressed, we might want to update pyright to 1.1.207 and enable the new diagnostic check to prevent future inconsistencies from being introduced.
Relatedly (but slightly tangentially), can anybody explain to me why classmethod.__new__ and classmethod.__init__ have different signatures in builtins? I've never really understood why, and there's no comment clarifying it:
Activity
Akuli commentedon Jan 13, 2022
For problem 2, I think we should just delete
_TokenType.__init__. You aren't supposed to instantiate_TokenTypeyourself anyway.The implementation is:
srittau commentedon Jan 14, 2022
Sounds like a good plan.
AlexWaygood commentedon Jan 15, 2022
Relatedly (but slightly tangentially), can anybody explain to me why
classmethod.__new__andclassmethod.__init__have different signatures inbuiltins? I've never really understood why, and there's no comment clarifying it:typeshed/stdlib/builtins.pyi
Lines 117 to 118 in 5d20635
(Same issue for
staticmethod.)