-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use abstract types from numbers
#7217
Comments
I don't think we can really do anything in typeshed. This is best handled on the type checker level. |
An approach like python/mypy#3186 (comment) could be feasible. |
A typing feature that allows stubs to register a type with another type, similar to what abcs provide at runtime, would be useful for those legacy features, though. |
I invested some energy a while back into seeing if you could do this, and I think the honest answer is that there's no way to make it work at typeshed. Mypy now gives a much more helpful error message if you try to use an abstract type from Closing as per the rationale in python/mypy#3186 (comment) |
Right now types declared in
numbers.pyi
are not used.This causes this problem:
But, in runtime:
float
is 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.pyi
Real.register(float)
inbuiltins.pyi
Real.register(float)
innumbers.pyi
(as runtime does)The text was updated successfully, but these errors were encountered: