10000 TYP,BUG: fix ``numpy.__dir__`` annotations by jorenham · Pull Request #26867 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

TYP,BUG: fix numpy.__dir__ annotations #26867

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 1 commit into from
Jul 18, 2024

Conversation

jorenham
Copy link
Member
@jorenham jorenham commented Jul 5, 2024

numpy.__dir__ annotated as a list[str], which is incorrect:

>>> import numpy as np
>>> callable(np.__dir__)
True

This PR changes its annotation to () -> Sequence[str].
Since the mutability of the return value isn't relevant (and considered to be practice), a collections.abc.Sequence was used as return type, as opposed to a list.

Although mostly irrelevant in this particular case, an additional benefit of using a Sequence in place of a list as (return) annotation, is that the type parameter of Sequence is covariant, whereas that of list is invariant.

@jorenham jorenham changed the title typ: fix numpy.__dir__ annotations TYP: fix numpy.__dir__ annotations Jul 5, 2024
@jorenham jorenham force-pushed the fix-__dir__-annotations branch from ee5c8bf to aedb52c Compare July 5, 2024 18:00
@charris charris changed the title TYP: fix numpy.__dir__ annotations TYP: fix numpy.__dir__ annotations Jul 5, 2024
@jorenham jorenham changed the title TYP: fix numpy.__dir__ annotations TYP,BUG: fix numpy.__dir__ annotations Jul 14, 2024
@jorenham jorenham force-pushed the fix-__dir__-annotations branch from aedb52c to a8a42f6 Compare July 15, 2024 17:10
Copy link
Member
@rgommers rgommers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jorenham. The change to annotate as a callable looks correct. Not sure Sequence vs. list matters here - let's give this a go.

@rgommers rgommers merged commit d583c54 into numpy:main Jul 18, 2024
67 of 68 checks passed
@rgommers rgommers added this to the 2.1.0 release milestone Jul 18, 2024
@jorenham jorenham deleted the fix-__dir__-annotations branch July 18, 2024 15:28
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.

2 participants
0