| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…callable When __new__ uses only *args and **kwargs, it is a passthrough that does not constrain the constructor signature. Step 2 of the conversion algorithm should produce no callable type in this case, leaving __init__ as the sole source of the constructor's signature. The conformance test (Class3) already expected this behaviour; the spec example for class B was inconsistent. Fixes python#2158.
| from a base class other than ``object``, a type checker should synthesize a | ||
| callable from the parameters and return type of that method after it is bound | ||
| to the class. | ||
| to the class. If the ``__new__`` method's only non-``cls`` parameters are |
There was a problem hiding this comment.
Why is this the right behavior? Also shouldn't there be requirements on the type annotations for the args/kwargs parameters?
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #2158.
The spec's step 2 for converting a constructor to a Callable type said that a __new__ method is always synthesized into a callable. The example for class B (which has __new__(cls, *args, **kwargs) -> Self and __init__(self, x: int) -> None) incorrectly showed:
However, the conformance test (Class3) already specified the correct behaviour:
When __new__ uses only *args and **kwargs as its non-cls parameters, it is a passthrough that defers all parameter constraints to __init__. Step 2 of the conversion algorithm should produce no callable type in this case. This is the behaviour already implemented by pyright, pycroscope, and zuban (all pass the conformance test).
Changes