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:
But, how can we type it? Options:
- Use a base class in
builtins.pyi
- Use
Real.register(float) in builtins.pyi
- Use
Real.register(float) in numbers.pyi (as runtime does)
Right now types declared in
numbers.pyiare not used.This causes this problem:
But, in runtime:
floatis registered to beReal, source: https://github.com/python/cpython/blob/12360aa159c42c7798fd14225d271e6fd84db7eb/Lib/numbers.py#L264Also:
complex: https://github.com/python/cpython/blob/12360aa159c42c7798fd14225d271e6fd84db7eb/Lib/numbers.py#L144int: https://github.com/python/cpython/blob/12360aa159c42c7798fd14225d271e6fd84db7eb/Lib/numbers.py#L393But, how can we type it? Options:
builtins.pyiReal.register(float)inbuiltins.pyiReal.register(float)innumbers.pyi(as runtime does)