Skip to content

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

Closed

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

Activity

  1. charris commented on May 17, 2022

    @charris
    Member

    @BvB93 Ping.

  2. BvB93 commented on May 17, 2022

    @BvB93
    Member

    I have to do a bit more checking, but creating a type-alias involving the npt._GenericAlias class (not instance) now appears to be broken, as typing expects an iterable for the __parameter__ attribute but instead gets a property descriptor object.

    @property
    def __parameters__(self) -> tuple[TypeVar, ...]:
    """Type variables in the ``GenericAlias``."""
    return super().__getattribute__("_parameters")

    The good news is that npt._GenericAlias isn'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.

  3. charris commented on May 18, 2022

    @charris
    Member

    @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?

  4. added
    triage reviewIssue/PR to be discussed at the next triage meeting
    on May 18, 2022
  5. BvB93 commented on May 18, 2022

    @BvB93
    Member

    Since the 1.22.x series is not expected to support Python 3.11

    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.

  6. removed this from the 1.23.1 release milestone on Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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