Skip to content

BUG: Python 3.11.0b1, test_generic_alias, TypeError: 'property' object is not iterable #21526

Closed
@hrnciar

Description

@hrnciar

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.0b1

Error 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.gz

NumPy/Python version information:

numpy 1.22.3
python 3.11.0b1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions