-
Notifications
You must be signed in to change notification settings - Fork 39
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
Fix type hints for Python versions < 3.10 #1897
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1897 +/- ##
=======================================
Coverage 92.03% 92.03%
=======================================
Files 234 234
Lines 12034 12034
=======================================
Hits 11075 11075
Misses 959 959
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
not sure this can be solved easily @bouweandela - have a look at this fastapi/typer#348 - am trying to pin |
I'm not sure if typer is related to this issue. What puzzles me is that dask uses a very similar configuration, so why is it not working for us? |
I thought typer was needed if we wanted to mess about with these type hints, I was wrong and I closed that PR - I am wondering though, maybe dask is using a different configuration of standards, or no mypy? Lemme have a look too |
I don't understand how pinning the Python version of mypy is supposed to solve this. Code like
is simply not valid code in Python<3.10 and will always raise these errors, no mypy involved whatsoever. |
that's why one needs to import |
But there is no https://github.com/dask/dask/blob/81f771e05f57cab2838534c319a9b81f6e5a00cd/dask/highlevelgraph.py#L1 |
not in this PR, Manu, since this a fixer PR - Bouwe put those _futures shtuff already, look at |
Ah, yes, that makes sense. Sorry, I didn't check that. I think I know what the problem is: def f(x: list[int]) -> dict[str, float]:
pass is allowed and works with Python >= 3.7 when using Example in our code:
However, as far as I can tell, it is not possible to use this feature in code that is always executed (e.g., to define custom types) in Python < 3.10 like we do here: ESMValCore/esmvalcore/_recipe/from_datasets.py Lines 20 to 21 in 25e508a
If you look at the error message we get, it's always those two lines. Other code that uses syntax like |
@schlunma I think that's a bingo! Since it doesn't seem to be mypy's fault here - let me see if we get the same with a lower mypy pin, if that's the case then we got us a runner |
yeah I reckon that's it - just figured it out it's not mypy that's at fault here, unless it's a dormant bug that's not been checked since a few versions ago - @schlunma you wanna make the changes you suggest directly in here and let's have us a test? I don't think @bouweandela would mind, since I've already hacked his PR quite a bit, before getting back to its original state 😁 |
@schlunma biutiful 😍 |
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.
boom! Looking great, cheers, Manu! @bouweandela I took the liberty make this RfR and approve it while I'm at it too
@bouweandela got a bit of time to look at this, buds? |
Description
Python 3.8 and 3.9 do not support
Python 3.8 does not support
even with
from __future__ import annotations
.In function signatures, the syntax is supported though.
Credits to @schlunma for figuring this out.
This pull request updates the code so the older Python versions are type hinted correctly.
Before you get started
Checklist
It is the responsibility of the author to make sure the pull request is ready to review. The icons indicate whether the item will be subject to the 🛠 Technical or 🧪 Scientific review.
To help with the number pull requests: