Repository navigation
Closed
Labels
00 - Bug41 - Static typingtriage reviewIssue/PR to be discussed at the next triage meetingIssue/PR to be discussed at the next triage meeting
Description
Describe the issue:
Numpy's tests are failing with Python 3.11.0b1. test_generic_alias fails with TypeError: 'property' object is not iterable during collection. The problem seems to be connected to this change in CPython python/cpython#31143. I am not sure if it's a regression in CPython or Numpy needs to be adapted.
Reproduce the code example:
Build numpy with Python 3.11.0b1Error message:
==================================== ERRORS ====================================
_____________ ERROR collecting typing/tests/test_generic_alias.py ______________
../../../../BUILDROOT/numpy-1.22.3-1.fc37.x86_64/usr/lib64/python3.11/site-packages/numpy/typing/tests/test_generic_alias.py:23: in <module>
FuncType = Callable[[Union[_GenericAlias, types.GenericAlias]], Any]
Any = typing.Any
Callable = typing.Callable
DType = numpy.dtype[+ScalarType]
DType_ref = numpy.dtype[+ScalarType]
NDArray = numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]]
NDArray_ref = numpy.ndarray[typing.Any, numpy.dtype[+ScalarType]]
ScalarType = +ScalarType
T1 = ~T1
T2 = ~T2
Tuple = typing.Tuple
Type = typing.Type
TypeVar = <class 'typing.TypeVar'>
Union = typing.Union
_GenericAlias = <class 'numpy.typing._generic_alias._GenericAlias'>
__builtins__ = <builtins>
__cached__ = '/builddir/build/BUILDROOT/numpy-1.22.3-1.fc37.x86_64/usr/lib64/python3.11/site-packages/numpy/typing/tests/__pycache__/test_generic_alias.cpython-311.pyc'
__doc__ = None
__file__ = '/builddir/build/BUILDROOT/numpy-1.22.3-1.fc37.x86_64/usr/lib64/python3.11/site-packages/numpy/typing/tests/test_generic_alias.py'
__loader__ = <_pytest.assertion.rewrite.AssertionRewritingHook object at 0x7f6280b124d0>
__name__ = 'numpy.typing.tests.test_generic_alias'
__package__ = 'numpy.typing.tests'
__spec__ = ModuleSpec(name='numpy.typing.tests.test_generic_alias', loader=<_pytest.assertion.rewrite.AssertionRewritingHook obje...uild/BUILDROOT/numpy-1.22.3-1.fc37.x86_64/usr/lib64/python3.11/site-packages/numpy/typing/tests/test_generic_alias.py')
annotations = _Feature((3, 7, 0, 'beta', 1), (3, 11, 0, 'alpha', 0), 16777216)
copy = <module 'copy' from '/usr/lib64/python3.11/copy.py'>
np = <module 'numpy' from '/builddir/build/BUILDROOT/numpy-1.22.3-1.fc37.x86_64/usr/lib64/python3.11/site-packages/numpy/__init__.py'>
pickle = <module 'pickle' from '/usr/lib64/python3.11/pickle.py'>
pytest = <module 'pytest' from '/usr/lib/python3.11/site-packages/pytest/__init__.py'>
sys = <module 'sys' (built-in)>
types = <module 'types' from '/usr/lib64/python3.11/types.py'>
weakref = <module 'weakref' from '/usr/lib64/python3.11/weakref.py'>
/usr/lib64/python3.11/typing.py:350: in inner
return func(*args, **kwds)
args = (typing.Union, (<class 'numpy.typing._generic_alias._GenericAlias'>, <class 'types.GenericAlias'>))
cached = <functools._lru_cache_wrapper object at 0x7f62815f5380>
func = <function _SpecialForm.__getitem__ at 0x7f62815fc7c0>
kwds = {}
/usr/lib64/python3.11/typing.py:450: in __getitem__
return self._getitem(self, parameters)
parameters = (<class 'numpy.typing._generic_alias._GenericAlias'>, <class 'types.GenericAlias'>)
self = typing.Union
/usr/lib64/python3.11/typing.py:661: in Union
return _UnionGenericAlias(self, parameters)
msg = 'Union[arg, ...]: each arg must be a type.'
parameters = (<class 'numpy.typing._generic_alias._GenericAlias'>, <class 'types.GenericAlias'>)
self = typing.Union
/usr/lib64/python3.11/typing.py:1317: in __init__
self.__parameters__ = _collect_parameters(args)
__class__ = <class 'typing._GenericAlias'>
_paramspec_tvars = False
args = (<class 'numpy.typing._generic_alias._GenericAlias'>, <class 'types.GenericAlias'>)
inst = True
name = None
origin = typing.Union
self = typing.Union[numpy.typing._generic_alias._GenericAlias, types.GenericAlias]
/usr/lib64/python3.11/typing.py:257: in _collect_parameters
for x in getattr(t, '__parameters__', ()):
E TypeError: 'property' object is not iterable
args = (<class 'numpy.typing._generic_alias._GenericAlias'>, <class 'types.GenericAlias'>)
parameters = []
t = <class 'numpy.typing._generic_alias._GenericAlias'>
=========================== short test summary info ============================
ERROR ../../typing/tests/test_generic_alias.py - TypeError: 'property' object...
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
1296 deselected, 1 error in 8.48s
https://download.copr.fedorainfracloud.org/results/@python/python3.11/fedora-rawhide-x86_64/04417682-numpy/builder-live.log.gzNumPy/Python version information:
numpy 1.22.3
python 3.11.0b1
Metadata
Metadata
Assignees
Labels
00 - Bug41 - Static typingtriage reviewIssue/PR to be discussed at the next triage meetingIssue/PR to be discussed at the next triage meeting
Activity
charris commentedon May 17, 2022
@BvB93 Ping.
BvB93 commentedon May 17, 2022
I have to do a bit more checking, but creating a type-alias involving the
npt._GenericAliasclass (not instance) now appears to be broken, astypingexpects an iterable for the__parameter__attribute but instead gets apropertydescriptor object.numpy/numpy/_typing/_generic_alias.py
Lines 93 to 96 in 59aad3c
The good news is that
npt._GenericAliasisn't used during runtime for python >= 3.9 anyway (besides in the test suite), so I'd expect stringifiying the relevant type alias in test_generic_alias.py will do the trick. I'll create a PR later after checking with python 3.11.0b1.charris commentedon May 18, 2022
@BvB93 I will do 1.22.4 in the next few days. Since the 1.22.x series is not expected to support Python 3.11, and the Python rc is not expected for several months, is there any reason not to tag this with 1.23.1 release?
BvB93 commentedon May 18, 2022
Ah, I didn't realize there wouldn't be any 1.22x python 3.11 wheels. No, if that's the case let's stick to a 1.23.1 tag.