-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
DEP: Deprecate numpy.typing.mypy_plugin
: The sequel
#28134
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
DEP: Deprecate numpy.typing.mypy_plugin
: The sequel
#28134
Conversation
Actually, ping @BvB93, since I think you would be the one with insight into this being a bad idea :). |
So what's the current (runtime) status of platform-dependent bitsizes of the numeric dtypes? Because while I fully agree that platform specificity is an annoyance, both for typing as well as runtime if I might add, as long as the reported types match their runtime equivalent it feels bit odd curious talk about "bad practice to have platform-dependent type annotations", as the reality of the situation here simply is platform dependent. |
Yeah, the "solution" is to use a (The problem with the union is of course that an I agree that this isn't strictly better, but am OK with it considering that this only works with mypy anyway. |
In case of static typing, platform-dependent types can also lead to platform-dependent typing errors, e.g. when def f(x: np.intp): ... is called with |
I'd be a bit careful with unions, as you generally can't freely downcast them to a non-union subtype with something as heavy handed as foo: tuple[int | str, ...] = ("hello", "world")
# Incompatible types in assignment (expression has type "tuple[int | str, ...]", variable has type "tuple[str, ...]")
bar: tuple[str, ...] = foo
Again, I don't really see how any of the provided arguments here are exclusive to static typing. Assuming that the function is annotated with something like
Yeah, that's fair. While, IMO, this is acceptable for downstream, if this is actively getting in the way of expanding numpy's typing tests suite with more type checkers then that's a different story. Though note that, either way, it's not uncommon to stumble upon tiny type-checker-specific differences in general every now and then. |
At runtime you can do things like Also note that anyone can write a mypy plugin themselves in case they want platform-specific types. I just don't think it's a good idea that we're the ones that provide it. I also don't think that the mypy plugin is compatible with the typing spec, which only allows for simple platform-specific checks that are limit to |
The typing spec also states the following:
https://typing.readthedocs.io/en/latest/guides/writing_stubs.html#all But the mypy plugin effectively removes exports such as So the plugin makes it impossible to do things like import numpy as np
from typing import TypeIs
type FloatEx = np.float80 | np.float96 | np.float128 | np.float256
def is_extended_precision_float(x: np.floating, /) -> TypeIs[FloatEx]: ... (on Python 3.13) |
This addresses the suggestions by @seberg in #28129, and adds a corresponding release note.