Skip to content

BUG: Fix shadowed reference of dtype in type stubs #20224

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 2 commits into from
Nov 2, 2021
Merged

BUG: Fix shadowed reference of dtype in type stubs #20224

merged 2 commits into from
Nov 2, 2021

Conversation

Azureblade3808
Copy link
Contributor

Direct use of dtype in ndarray or generic would be shadowed by
ndarray.dtype or generic.dtype, so an alias is used here.

See #20223.

Direct use of `dtype` in `ndarray` or `generic` would be shadowed by
`ndarray.dtype` or `generic.dtype`, so an alias is used here.

See #20223.
Copy link
Member

@BvB93 BvB93 left a comment

Choose a reason for hiding this comment

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

There is a similar naming conflict involving dtype.str that I would suggest addressing as well.

numpy/numpy/__init__.pyi

Lines 923 to 926 in d5f6618

# Leave str and type for end to avoid having to use `builtins.str`
# everywhere. See https://github.com/python/mypy/issues/3775
@property
def str(self) -> builtins.str: ...

Besides that, the dtype changes look good to me; I know mypy can deal with the name shadowing as long as the offending attribute is at the bottom of the class, but this does not seem to be universal among type checkers.

@BvB93 BvB93 added the 09 - Backport-Candidate PRs tagged should be backported label Oct 29, 2021
@BvB93 BvB93 added this to the 1.21.4 release milestone Oct 29, 2021
@BvB93 BvB93 merged commit 11ee995 into numpy:main Nov 2, 2021
@BvB93
Copy link
Member

BvB93 commented Nov 2, 2021

Thanks @Azureblade3808.

@BvB93 BvB93 removed this from the 1.21.4 release milestone Nov 2, 2021
@BvB93 BvB93 removed the 09 - Backport-Candidate PRs tagged should be backported label Nov 2, 2021
@Azureblade3808 Azureblade3808 deleted the use-alias-for-dtype-in-type-stubs branch November 3, 2021 02:53
@charris charris changed the title BUG: Fix shadowed reference of dtype in type stubs BUG: Fix shadowed reference of dtype in type stubs Nov 5, 2021
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.

BUG: In "numpy/__init__.pyi", type dtype referenced in ndarray.item(...) needs to be aliased
2 participants