[
https://issues.apache.org/jira/browse/BEAM-12920?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jonathan Hourany updated BEAM-12920:
------------------------------------
Description:
In Python 3.9 the test
[test_convert_bare_types|https://github.com/apache/beam/blob/6c1c19d6c711babf5f5f042fa465be20948caff6/sdks/python/apache_beam/typehints/native_type_compatibility.py#L40]
fails when testing the following Generator test case
{code:python}
test_cases += [
(
'bare generator',
typing.Generator,
typehints.Generator[typehints.TypeVariable('T_co')]),
]
{code}
Raising the following {{ValueError}}
{noformat}
./sdks/python/apache_beam/typehints/native_type_compatibility_test.py::NativeTypeCompatibilityTest::test_convert_bare_types
Failed: [undefined]ValueError: Unsupported Generator with no arguments.
{noformat}
----
The immediate cause may be stemming from
[_get_args|https://github.com/apache/beam/blob/6c1c19d6c711babf5f5f042fa465be20948caff6/sdks/python/apache_beam/typehints/native_type_compatibility.py#L40]
which attempts to access a type's ___args___ attribute. In Python 3.9 bare
generators no long instantiate with a default ___args___ attribute by default.
Only when instantiate with args do they get one (see example below).
However, despite it's name the test doesn't create a generator that's totally
bare, so the deeper cause may be coming from the way {{typinghints.Generator}}
is constructed.
h3. Examples
{code:python}
# Python 3.7.5
In [1]: from typing import Generator
----
In [2]: Generator.__args__
Out[2]: (+T_co, -T_contra, +V_co)
{code}
----
{code:python}
# Python 3.9.7
In [1]: from typing import Generator
In [2]: Generator.__args__
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-3e272b948083> in <module>
----> 1 Generator.__args__
~/.pyenv/versions/3.9.7/lib/python3.9/typing.py in __getattr__(self, attr)
704 if '__origin__' in self.__dict__ and not _is_dunder(attr):
705 return getattr(self.__origin__, attr)
--> 706 raise AttributeError(attr)
707
708 def __setattr__(self, attr, val):
AttributeError: __args__
In [3]: # Initializing with args, however, creates the needed attr
In [4]: Generator[int, int, int].__args__
Out[4]: (int, int, int)
{code}
was:
In Python 3.9 the test [test_convert_bare_types|] fails when testing the
following Generator test case
{code:python}
test_cases += [
(
'bare generator',
typing.Generator,
typehints.Generator[typehints.TypeVariable('T_co')]),
]
{code}
Raising the following {{ValueError}}
{noformat}
./sdks/python/apache_beam/typehints/native_type_compatibility_test.py::NativeTypeCompatibilityTest::test_convert_bare_types
Failed: [undefined]ValueError: Unsupported Generator with no arguments.
{noformat}
----
The immediate cause may be stemming from [get_args|] which attempts to access a
type's ___args___ attribute. In Python 3.9 bare generators no long instantiate
with a default ___args___ attribute by default. Only after being passed args do
they get one (see below).
However, despite it's name the test doesn't create a generator that's totally
bare, so the deeper cause may be coming from the way {{typinghints.Generator}}
is constructed.
Examples:
{code:python}
# Python 3.7.5
In [1]: from typing import Generator
----
In [2]: Generator.__args__
Out[2]: (+T_co, -T_contra, +V_co)
{code}
----
{code:python}
# Python 3.9.7
In [1]: from typing import Generator
In [2]: Generator.__args__
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-3e272b948083> in <module>
----> 1 Generator.__args__
~/.pyenv/versions/3.9.7/lib/python3.9/typing.py in __getattr__(self, attr)
704 if '__origin__' in self.__dict__ and not _is_dunder(attr):
705 return getattr(self.__origin__, attr)
--> 706 raise AttributeError(attr)
707
708 def __setattr__(self, attr, val):
AttributeError: __args__
In [3]: # Initializing with args, however, creates the needed attr
In [4]: Generator[int, int, int].__args__
Out[4]: (int, int, int)
{code}
> Convert To Bare Types Fails on Generators in Python 3.9
> -------------------------------------------------------
>
> Key: BEAM-12920
> URL: https://issues.apache.org/jira/browse/BEAM-12920
> Project: Beam
> Issue Type: Bug
> Components: test-failures
> Affects Versions: 2.32.0
> Environment: Python 3.9.7
> Linux Mint 20.2, Kernel: 5.4.0-84-generic
> Reporter: Jonathan Hourany
> Priority: P2
>
> In Python 3.9 the test
> [test_convert_bare_types|https://github.com/apache/beam/blob/6c1c19d6c711babf5f5f042fa465be20948caff6/sdks/python/apache_beam/typehints/native_type_compatibility.py#L40]
> fails when testing the following Generator test case
> {code:python}
> test_cases += [
> (
> 'bare generator',
> typing.Generator,
> typehints.Generator[typehints.TypeVariable('T_co')]),
> ]
> {code}
> Raising the following {{ValueError}}
> {noformat}
> ./sdks/python/apache_beam/typehints/native_type_compatibility_test.py::NativeTypeCompatibilityTest::test_convert_bare_types
> Failed: [undefined]ValueError: Unsupported Generator with no arguments.
> {noformat}
> ----
> The immediate cause may be stemming from
> [_get_args|https://github.com/apache/beam/blob/6c1c19d6c711babf5f5f042fa465be20948caff6/sdks/python/apache_beam/typehints/native_type_compatibility.py#L40]
> which attempts to access a type's ___args___ attribute. In Python 3.9 bare
> generators no long instantiate with a default ___args___ attribute by
> default. Only when instantiate with args do they get one (see example below).
> However, despite it's name the test doesn't create a generator that's
> totally bare, so the deeper cause may be coming from the way
> {{typinghints.Generator}} is constructed.
> h3. Examples
> {code:python}
> # Python 3.7.5
> In [1]: from typing import Generator
> ----
> In [2]: Generator.__args__
> Out[2]: (+T_co, -T_contra, +V_co)
> {code}
> ----
> {code:python}
> # Python 3.9.7
> In [1]: from typing import Generator
> In [2]: Generator.__args__
> ---------------------------------------------------------------------------
> AttributeError Traceback (most recent call last)
> <ipython-input-2-3e272b948083> in <module>
> ----> 1 Generator.__args__
> ~/.pyenv/versions/3.9.7/lib/python3.9/typing.py in __getattr__(self, attr)
> 704 if '__origin__' in self.__dict__ and not _is_dunder(attr):
> 705 return getattr(self.__origin__, attr)
> --> 706 raise AttributeError(attr)
> 707
> 708 def __setattr__(self, attr, val):
> AttributeError: __args__
> In [3]: # Initializing with args, however, creates the needed attr
> In [4]: Generator[int, int, int].__args__
> Out[4]: (int, int, int)
> {code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)