-
-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Closed
Description
Proposed new feature or change:
Python 3.11 will add the new typing.assert_type function, which is used for validating that two types are equivalent while static type checking. Switching from the type-comments, currently used for validating the revealed type, to typing.assert_type has a number advantages:
- It finally allows to get rid of the old type-comments, which add a lot of visual clutter.
- It makes it much easier to use features like type-aliases.
typing.assert_typeis agnostic w.r.t. the particular type checkers, so this means we could in principle easily run the tests with other type checkers besides mypy.
Note that a backport is already available in typing-extensions and fully supported as of the latest mypy release (0.950).
Examples
AR_c16: NDArray[np.complex128]
AR_c = NDArray[np.complexfloating]
typing.assert_type(np.fft.fftfreq(np.int64(), AR_c16), AR_c)