Skip to content

TYP: append: add @deprecated overloads for python scalar coversions - #33047

Open
jorenham wants to merge 1 commit into
numpy:mainfrom
jorenham:typing/append/deprecated
Open

jorenham wants to merge 1 commit into
numpy:mainfrom
jorenham:typing/append/deprecated

Conversation

@jorenham

Copy link
Copy Markdown
Member

This is the static typing counterpart of #32642.


Pair programmed with AI (mostly me though).

@jorenham jorenham left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ngoldbaum

Copy link
Copy Markdown
Member

I asked an AI model to try to find spots where the type changes disagree with runtime behavior. It found:

import warnings
import numpy as np

warnings.simplefilter("always", FutureWarning)
a = np.array([1], dtype=np.float32)
np.append(a, True)           # mypy: deprecated; runtime: no warning
np.append(a, np.float64(1))  # mypy: deprecated; runtime: no warning
np.append("a", 1)            # mypy: no diagnostic; runtime: FutureWarning

The True one is arguable about whether we should deprecate it (bool is a subclass of int after all). The others I think are bugs in your type changes. These three are the only class of issues I could find.

@jorenham

Copy link
Copy Markdown
Member Author

Hm good catch.
The first (True) one I think would make sense to also deprecate.
The second (float64) one is tricky because float64 subclasses float, so I'd have to hack my way around that.
The third one ("a") would be tricky to @deprecate, because np.str_ subclasses str. I could also hack around that I guess.

This branch has not been deployed

No deployments
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