Skip to content

Inconsistencies between __init__ and __new__ #6905

@erictraut

Description

@erictraut

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.

  1. The class WeakMethod in weakref.pyi defines a __new__ that is incompatible with the __init__ declared in its parent class ReferenceType.
  2. The class _TokenType in pygments/token.pyi defines an __init__ that is incompatible with the __new__ in tuple[str].
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions