-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
drop support for python=3.9
#8937
base: main
Are you sure you want to change the base?
Conversation
# We require a "hack" to tell type checkers that e.g. Variable + DataArray = DataArray | ||
# In reality this returns NotImplementes, but this is not a valid type in python 3.9. | ||
# In reality this returns NotImplemented, but this is not a valid type in python 3.9. | ||
# Therefore, we return DataArray. In reality this would call DataArray.__add__(Variable) | ||
# TODO: change once python 3.10 is the minimum. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@headtr1ck, can you explain (or directly push a fix, if possible) what you meant by this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I will be able to code anytime soon, so here an explanation first:
If you do operators, python checks the left obj First. Since DataArray is an array-like (and therefore part of VariableCompatible), the type checker thinks that Variable + DataArray = Variable, which is incorrect.
If you want to follow the runtime behavior, you should return NotImplemented, unfortunately it is not a valid type in Python 3.9. Therefore we return DataArray directly.
Now the "fix" would be to change the return type to NotImplemented and check if it works in Python >=3.10 (I have not actually confirmed that, in case just leave things like they are since it is technically working).
This means we could replace |
Shouldn't pyupgrade / ruff do that for us? |
it does, but only parts of it (other fixes it deems unsafe so they require manual intervention). I don't have time to go through each of them this week, but feel to push any of these directly to this PR. |
Because of [NEP29](https://numpy.org/neps/nep-0029-deprecation_policy) NumPy only supports ≥3.10 now. Also, Zarr, NetworkX, and ([soon](pydata/xarray#8937)) Xarray will support only ≥3.10.
According to our policy (and NEP-29) we can drop support for
python=3.9
since about a week ago. Interestingly, SPEC0 says we could have started doing this about half a year ago (Q4 2023).We could delay this until we have a release that is compatible with
numpy>=2.0
, though (numpy>=2.1
will drop support forpython=3.9
).whats-new.rst