Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: Refactor the typing "reveal" tests using typing.assert_type #21505

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

Closed
BvB93 opened this issue May 14, 2022 · 0 comments · Fixed by #24635
Closed

ENH: Refactor the typing "reveal" tests using typing.assert_type #21505

BvB93 opened this issue May 14, 2022 · 0 comments · Fixed by #24635

Comments

@BvB93
Copy link
Member

BvB93 commented May 14, 2022

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_type is 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant