-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
DOC: Add information (maybe just release note) for typing regressions #28077
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
Comments
It's more that we've made progress towards supporting shape typing; it hasn't been introduced yet.
Do you mean that
Yes, this shouldn't have happened. I aim to fix it within two weeks.
True; we have never claimed that we support shape-typing, only that we're working towards it, and that it's difficult to achieve.
I'm not sure if this will help much, but it's worth a short, and it will be enabled by default in mypy 2.0 anyway.
https://github.com/erictraut/mypy_issues helps explain why
Maybe it's a good idea to add a note to the |
@jorenham do you have time to write some (brief) guidance? We can even start here and then see how to integrate it into the 2.2 release notes or so. About mypy, I think we should explicitly mention the redefinition thing and otherwise just note that we tend to see more issues with |
At least not for the coming days. I need to release the next
I don't think we can afford to ditch mypy ourselves, not while we still have a non-neglicable amount of users that still use it. A little bird told me that there'll be some exciting big changes coming to numpy-typing in the near future, and that it'll be 100% opt-in.
and more like
At the moment I can't really say when exactly that (alleged) change will come, but the little bird told me that a certain someone will work on it once that certain someone as fixed set of certain numpy issues. |
Just brainstorming: When updating to NumPy 2.2, users may unfortunately experience typing regressions largely due to improved typing information. The biggest change is seeing errors such as:
which can happen for two reasons:
A second change seen more commonly is a newly reported typing mismatch for In general, we have experienced more issues with Something about future work... dunno what. The main point is, I can't say if this is complete and is actually the information. We can hint about that future work and note that this is necessary to make future work happen. |
I would make it clear to the user what their expectation can be, and what we are doing. E.g., something like:
Let's figure out the list of items we want to discuss; that's a lower bar to meet, and I'd be happy to take that list and expand it into full sentences. |
* Widen Array1D to fix changes to numpy shape numpy/numpy#28077 (comment) * Fix error message output
* Widen Array1D to fix changes to numpy shape numpy/numpy#28077 (comment) * Fix error message output
Any update on the current recommendation for shape typed code when updating to Numpy 2.2? If I understood the conversation so far, this concerns situations where we started using shape types for better documenting array dimensions like this: Array1D = np.ndarray[tuple[int], np.dtype[np.uint8]]
Array2D = np.ndarray[tuple[int, int], np.dtype[np.uint8]]
def test(data_2d: Array2D) -> Array1D:
# Mypy + Numpy 2.2: Incompatible return value type
# (got "ndarray[tuple[int, ...], ...]", expected "ndarray[tuple[int], ...]")
return data_2d[:, 0] The current recommendation is to remove the shape types on our end? It's a bit sad because being able to communicate how array structures look like is a big win, even without having checks for it. There isn't by any chance a way to make type checkers opt out of checking shape types again? Like, making the Numpy-Mypy-Plugin override shape types to |
For now that's indeed for the best.
I completely agree. That's why we're currently working hard so that you'd be able to do something similar like this in the future. But since there's a good that the api will be different from your example, it might not be compatible with the shape-typing approach from your example. In case you're interested in the details, the shape-typing progress can be followed at https://github.com/numpy/numtype. But note that there's no official release, and not a lot of documentation yet, as it's all a bit experimental at the moment.
In NumPy 2.3 the mypy plugin will actually be deprecated. There are many reasons for that, but one of the most important one is because we aim to support multiple type-checkers, such as pyright. That requires minimizing the differences in behavior between different type-checkers. On a related note, the upcoming NumPy 2.3 will make the shape-type of |
As you can see at #28982 (comment), this change can lead to some typing errors in downstream libraries. So including it in a patch release would be too risky, as far as I'm concerned. |
It may be helpful to have a (likely very brief) section on how to deal with typing regressions, and I think it would be just fine to amend the 2.2 release notes (and maybe add a link to that for 2.2.1 and/or 2.2.2).
We should also add a "Static typing" section to the release notes, I think.
There were two (main?) regressions for users (whether they are just fixes doesn't matter):
floating
typing.And while I know that we have the following options:
floating
this is unfortunate and users should open an issue where necessary, because we can hopefully fix it.--allow-redefinition
inmypy
for unannotated code (with caveats).mypy
(I am not sure how feasible this was for @stefanv!)So in the end, there is almost nothing here, but considering how long the discussion was, maybe it is helpful to do it even if it isn't too many users who need it in the end (I am honestly not sure).
Even better would be to improve the "how to type NumPy"/
numpy.typing
documentation, but that would seem like a lot of work. Although, adding a.. note::
to not type shapes seems very prudent?The text was updated successfully, but these errors were encountered: