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:
Chunk = Union[Tuple[Key, xarray.Dataset], Tuple[Key, Tuple[xarray.Dataset, ...]]]
In versions of Python before 3.10, this causes no problems. However, in 3.10 (and presumably onward), this type leads to a error:
ValueError: expecting type typing.Tuple[xarray_beam._src.core.Key, xarray.core.dataset.Dataset] to have arity 0, had arity 2 instead
I've looked a bit in depth at the sources, and I think this is the root cause of the issue:
|
def match_is_named_tuple(user_type): |
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 a NamedTuple (which it is not). Further, when I change the type annotation to tuple, no errors occur. It seems like the recent addition of type-annotations with built-ins will require how match_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
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
Tupleas 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_tupleis implemented:As a workaround, users can use the
tupletuple 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