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.
I just implemented a new check in pyright called
reportInconsistentConstructorthat 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.
WeakMethodinweakref.pyidefines a__new__that is incompatible with the__init__declared in its parent classReferenceType._TokenTypeinpygments/token.pyidefines an__init__that is incompatible with the__new__intuple[str].CascadeOptionsinSQLAlchemy/sqlalchemy/orm/util.pyidefines a__new__that is incompatible with the__init__in its parent classfrozenset[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.