-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Bug]: Tuple
is confused for a NamedTuple
across Python versions (3.9 vs 3.10).
#24685
Comments
Thanks for reporting. We should look into this a part of Python 3.10 upgrade. |
actually, this is for 3.10, not 3.11 |
Thanks for opening this issue and looking so deeply into its cause, @alxmrs. Just chiming in to say that this issue is currently blocking us upgrading to Python 3.10 in Pangeo Forge, xref pangeo-forge/pangeo-forge-recipes#470. @tvalentyn are you open to PRs to fix this? I may be able to devote a little time in the coming weeks, if you don't already have someone looking into this. |
I'm looking into this right now along with #23366 (which points out that we currently do not handle the built-in |
Thanks, @jrmccluskey! |
I'm actually having a bit of trouble reproducing the error described here and in pangeo-forge/pangeo-forge-recipes#470. The only 0-arity types we handle are For any parameterized definition of |
I suspect simplest fix would be to add one more hasattr here like edit: Oh I'm being dumb as I was thinking of an instance not NamedTuple itself. NamedTuple is extra weird as it's not actually a class, but a function in python 3.10. edit 2:
So I think hasattr for type does work well too. |
What happened?
To me, this is a really interesting corner case! Here's what's going on:
I'm updating an operator in XArray-Beam google/xarray-beam#69. I have a type that I've defined as follows:
In versions of Python before 3.10, this causes no problems. However, in 3.10 (and presumably onward), this type leads to a error:
I've looked a bit in depth at the sources, and I think this is the root cause of the issue:
beam/sdks/python/apache_beam/typehints/native_type_compatibility.py
Line 108 in 4886bdf
This function, which checks if the tuple has annotations to test if it's a named tuple, doesn't behave as I'd expect. In Python 3.10, it treats
Tuple
as aNamedTuple
(which it is not). Further, when I change the type annotation totuple
, no errors occur. It seems like the recent addition of type-annotations with built-ins will require howmatch_is_named_tuple
is implemented:As a workaround, users can use the
tuple
tuple annotation via__futures__
for Python 3.7 and later.https://peps.python.org/pep-0585/#implementation
Issue Priority
Priority: 2 (default / most bugs should be filed as P2)
Issue Components
The text was updated successfully, but these errors were encountered: