Closed as not planned
Description
Right now types declared in numbers.pyi
are not used.
This causes this problem:
from numbers import Real
def test(f: Real) -> Real:
return f
test(1.32)
# error: Argument 1 to "test" has incompatible type "float"; expected "Real"
But, in runtime:
float
is registered to beReal
, source: https://github.com/python/cpython/blob/12360aa159c42c7798fd14225d271e6fd84db7eb/Lib/numbers.py#L264
Also:complex
: https://github.com/python/cpython/blob/12360aa159c42c7798fd14225d271e6fd84db7eb/Lib/numbers.py#L144int
: https://github.com/python/cpython/blob/12360aa159c42c7798fd14225d271e6fd84db7eb/Lib/numbers.py#L393
But, how can we type it? Options:
- Use a base class in
builtins.pyi
- Use
Real.register(float)
inbuiltins.pyi
- Use
Real.register(float)
innumbers.pyi
(as runtime does)
Metadata
Metadata
Assignees
Labels
No labels