Skip to content

TYP: Transparent ndarray unary operator method signatures #27659

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 4 commits into from
Oct 29, 2024

Conversation

jorenham
Copy link
Member

The following unary arithmetic operators of numpy.ndarray have been simplified and improved:

  • __abs__
  • __invert__
  • __neg__
  • __pos__

These will now return shape-type and the specific ndarray subtype if relevant. Type-tests were added to confirm the correct behavior, which required working around a tricky mypy bug (python/mypy#14070).

Additionally, the typing errors in the numeric builtin-type-conversion methods of ndarray have been fixes, so that pyright/pylance will now also be able to infer their return types:

  • __index__
  • __int__
  • __float__
  • __complex__

These changes should in general be backwards-compatible.

@charris charris merged commit dfd1180 into numpy:main Oct 29, 2024
61 checks passed
@jorenham jorenham deleted the typing/transparent-ndarray-ops branch October 29, 2024 20:56
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