Skip to content
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

BUG: np.bool_ alias not exported in __init__.pyi with 2.0.0rc1 #26199

Closed
jorenham opened this issue Apr 3, 2024 · 3 comments · Fixed by #26210
Closed

BUG: np.bool_ alias not exported in __init__.pyi with 2.0.0rc1 #26199

jorenham opened this issue Apr 3, 2024 · 3 comments · Fixed by #26210

Comments

@jorenham
Copy link
Member

jorenham commented Apr 3, 2024

Describe the issue:

Type checkers (tested with pyright==1.1.356 in strict mode) don't recognize np.bool_ as alias for np.bool on numpy==2.0.0rc1.

Unless I'm missing something, this is because bool_ is missing in __init__.pyi.

Reproduce the code example:

import numpy as np

type NpBool = np.bool_  # results in pyright errors

Error message:

error: Type of "bool_" is unknown (reportUnknownMemberType)
error: "bool_" is not a known member of module "numpy" (reportAttributeAccessIssue)

Python and NumPy Versions:

2.0.0rc1
3.12.2 (main, Feb 25 2024, 16:35:05) [GCC 11.4.0]

Runtime Environment:

No response

Context for the issue:

This makes it impossible to add support for both numpy 1 and 2 in typed python packages, e.g. in https://github.com/jorenham/Lmo/blob/master/lmo/typing.py

@rgommers
Copy link
Member

rgommers commented Apr 3, 2024

Unless I'm missing something, this is because bool_ is missing in __init__.pyi.

This was done in gh-25080. There's some discussion in that PR; if needed we can revisit the decision, but in principle non-recommended aliases (as well as deprecated items) are not exposed in .pyi files.

In principle I don't see an issue with adding back np.bool_ as an alias of np.bool for a while (eventually we should remove it though I think). I think it wasn't discussed carefully enough in gh-25080. The hard work done there was to update all the .pyi files to make np.bool canonical and used everywhere in the 2.0 type stubs. At the end np.bool_ could have been added back though, since package authors cannot unconditionally use np.bool yet as long as they support numpy 1.x.

@rgommers rgommers added this to the 2.0.0 release milestone Apr 3, 2024
@mtsokol mtsokol self-assigned this Apr 3, 2024
@jorenham
Copy link
Member Author

jorenham commented Apr 3, 2024

The np.bool_ being an alias is mentioned in
https://github.com/numpy/numpy/blob/v2.0.0rc1/doc/source/release/2.0.0-notes.rst#changes.

But surprisingly, I can't seem to find anything about this (breaking) np.bool change in the migration guide. I'll open a new issue for this

@seberg
Copy link
Member

seberg commented Apr 3, 2024

Since np.bool_ is the only way to write things compatible and it is not yet deprecated, I think it should be re-added.

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.

4 participants