-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
TYP: Concrete float64
and complex128
scalar types with builtin bases
#27334
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
Conversation
Thanks @jorenham . I'll go with your judgement here. |
DOC: Add release notes for #27334
@jorenham Thanks for implementing these changes to resolve static type checking issues involving Python and numpy float types. At the time you implement them, did you also consider covering the case below (assigning a I installed latest numpy with your changes using: |
You're assigning a supertype to a subtype here; that's not valid. You also can't assign an int to a bool, but you can assign a bool to an int. |
At runtime,
numpy.float64
subclassesbuiltins.float
, andnumpy.complex128
subclassesbuiltins.complex
. But the typing stubs currently do not reflect this. The consequence is that e.g.spam: float = np.float64(22 / 7)
will be marked as an error by static type-checkers.This PR introduces concrete types for
float64
andcomplex128
that, like at runtime, (also) inherit from thefloat
andcomplex
builtin types, respectively.Note that that the amount of type-tests had to be adjusted to accommodate this change, doesn't reflect the impact of this change on existing codebases is this case. This is becaue the
typing.assert
that is used in these type-tests, requires the exact type to match, soassert_type
considersfloating[_64Bit]
andfloat64
as totally different types, even thoughfloat64 <: floating[_64Bit]
. So for existing typing annotations this won't require a change.Fixes #23081
Fixes #21906
Fixes #23663