Constructors in subclasses should have same signature or not? #1305
Replies: 2 comments
-
Pyright intentionally exempts |
Beta Was this translation helpful? Give feedback.
-
Yes, the docs here seem wrong, or at least inconsistent with current practice. They do reflect the text of PEP 484: https://peps.python.org/pep-0484/#the-type-of-class-objects. In practice (as Eric also said), type checkers allow incompatible |
Beta Was this translation helpful? Give feedback.
-
The Python docs state¹
Does this only apply to classes that we put as arguments to
Type
or to all classes? On the one hand, subclasses have differing constructor signatures all the time, e.g. dataclasses. On the other hand, without this constraint we can do things like this:which Pyright doesn't find any errors in.
Beta Was this translation helpful? Give feedback.
All reactions