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

Skip to content

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

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

Merged
merged 5 commits into from
Sep 4, 2023

Conversation

BvB93
Copy link
Member

@BvB93 BvB93 commented Sep 4, 2023

Closes #21505

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 with fairly minimal changes to the relevant test functions.

Probably want to merge after #24634 and #24587 to minimize merge conflicts.

Examples

- reveal_type(np.unique(AR_f8))  # E: ndarray[Any, dtype[{float64}]]
+ assert_type(np.unique(AR_f8), npt.NDArray[np.float64])

@BvB93 BvB93 added the 09 - Backport-Candidate PRs tagged should be backported label Sep 4, 2023
@BvB93
Copy link
Member Author

BvB93 commented Sep 4, 2023

@charris I'd say that this might be worth backporting to 1.26 (marked as such as of now(, though could you let me handle the backport? The rebasing will require a bit of work as a number of 2.0-only changes will have to be reverted.

@charris charris merged commit 4db6fce into numpy:main Sep 4, 2023
@charris
Copy link
Member

charris commented Sep 4, 2023

Thanks Bas.

@BvB93 BvB93 deleted the assert_type branch September 4, 2023 17:54
@BvB93 BvB93 removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Refactor the typing "reveal" tests using typing.assert_type
2 participants