nptyping: 2.3.0: pytest is failing

I’m packaging your module as an rpm package so I’m using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

  • python3 -sBm build -w --no-isolation
  • because I’m calling build with --no-isolation I’m using during all processes only locally installed modules
  • install .whl file in </install/prefix>
  • run pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-nptyping-2.3.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-nptyping-2.3.0-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra --ignore tests/test_package_info.py
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/nptyping-2.3.0
plugins: typeguard-2.13.3
collected 91 items

tests/test_assert_isinstance.py ...                                                                                                                                  [  3%]
tests/test_base_meta_classes.py .........                                                                                                                            [ 13%]
tests/test_beartype.py ....                                                                                                                                          [ 17%]
tests/test_lib_export.py .                                                                                                                                           [ 18%]
tests/test_mypy.py FFFFFFFFFF.                                                                                                                                       [ 30%]
tests/test_ndarray.py ..........................                                                                                                                     [ 59%]
tests/test_performance.py .                                                                                                                                          [ 60%]
tests/test_pyright.py ..                                                                                                                                             [ 62%]
tests/test_recarray.py ...                                                                                                                                           [ 65%]
tests/test_shape.py .....                                                                                                                                            [ 71%]
tests/test_shape_expression.py ...                                                                                                                                   [ 74%]
tests/test_structure.py ........                                                                                                                                     [ 83%]
tests/test_structure_expression.py ........                                                                                                                          [ 92%]
tests/test_typeguard.py ....                                                                                                                                         [ 96%]
tests/test_wheel.py F..                                                                                                                                              [100%]

================================================================================= FAILURES =================================================================================
_______________________________________________________________ MyPyTest.test_mypy_accepts_ndarray_with_any ________________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_ndarray_with_any>

    def test_mypy_accepts_ndarray_with_any(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            from nptyping import NDArray


            NDArray[Any, Any]
        """
        )
>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:26: AssertionError
______________________________________________________________ MyPyTest.test_mypy_accepts_ndarray_with_shape _______________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_ndarray_with_shape>

    def test_mypy_accepts_ndarray_with_shape(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            from nptyping import NDArray, Shape


            NDArray[Shape["3, 3"], Any]
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:39: AssertionError
____________________________________________________________ MyPyTest.test_mypy_accepts_ndarray_with_structure _____________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_ndarray_with_structure>

    def test_mypy_accepts_ndarray_with_structure(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            from nptyping import NDArray, RecArray, Structure


            NDArray[Any, Structure["x: Float, y: Int"]]
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:52: AssertionError
________________________________________________________ MyPyTest.test_mypy_accepts_ndarrays_as_function_arguments _________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_ndarrays_as_function_arguments>

    def test_mypy_accepts_ndarrays_as_function_arguments(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            import numpy as np
            from nptyping import NDArray, Shape


            def func(_: NDArray[Shape["2, 2"], Any]) -> None:
                ...


            func(np.array([1, 2]))  # (Wrong shape though)
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:90: AssertionError
__________________________________________________________ MyPyTest.test_mypy_accepts_ndarrays_as_variable_hints ___________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_ndarrays_as_variable_hints>

    def test_mypy_accepts_ndarrays_as_variable_hints(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            import numpy as np
            from nptyping import NDArray


            arr: NDArray[Any, Any] = np.array([1, 2, 3])
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:104: AssertionError
________________________________________________________________ MyPyTest.test_mypy_accepts_nptyping_types _________________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_nptyping_types>

    def test_mypy_accepts_nptyping_types(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            import numpy as np
            import numpy.typing as npt
            from nptyping import (
                NDArray,
                Number,
                Bool,
                Bool8,
                Object,
                Object0,
                Datetime64,
                Integer,
                SignedInteger,
                Int8,
                Int16,
                Int32,
                Int64,
                Byte,
                Short,
                IntC,
                IntP,
                Int0,
                Int,
                LongLong,
                Timedelta64,
                UnsignedInteger,
                UInt8,
                UInt16,
                UInt32,
                UInt64,
                UByte,
                UShort,
                UIntC,
                UIntP,
                UInt0,
                UInt,
                ULongLong,
                Inexact,
                Floating,
                Float16,
                Float32,
                Float64,
                Half,
                Single,
                Double,
                Float,
                LongDouble,
                LongFloat,
                ComplexFloating,
                Complex64,
                Complex128,
                CSingle,
                SingleComplex,
                CDouble,
                Complex,
                CFloat,
                CLongDouble,
                CLongFloat,
                LongComplex,
                Flexible,
                Void,
                Void0,
                Character,
                Bytes,
                String,
                Bytes0,
                Unicode,
                Str0,
            )

            NDArray[Any, Number]
            NDArray[Any, Bool]
            NDArray[Any, Bool8]
            NDArray[Any, Object]
            NDArray[Any, Object0]
            NDArray[Any, Datetime64]
            NDArray[Any, Integer]
            NDArray[Any, SignedInteger]
            NDArray[Any, Int8]
            NDArray[Any, Int16]
            NDArray[Any, Int32]
            NDArray[Any, Int64]
            NDArray[Any, Byte]
            NDArray[Any, Short]
            NDArray[Any, IntC]
            NDArray[Any, IntP]
            NDArray[Any, Int0]
            NDArray[Any, Int]
            NDArray[Any, LongLong]
            NDArray[Any, Timedelta64]
            NDArray[Any, UnsignedInteger]
            NDArray[Any, UInt8]
            NDArray[Any, UInt16]
            NDArray[Any, UInt32]
            NDArray[Any, UInt64]
            NDArray[Any, UByte]
            NDArray[Any, UShort]
            NDArray[Any, UIntC]
            NDArray[Any, UIntP]
            NDArray[Any, UInt0]
            NDArray[Any, UInt]
            NDArray[Any, ULongLong]
            NDArray[Any, Inexact]
            NDArray[Any, Floating]
            NDArray[Any, Float16]
            NDArray[Any, Float32]
            NDArray[Any, Float64]
            NDArray[Any, Half]
            NDArray[Any, Single]
            NDArray[Any, Double]
            NDArray[Any, Float]
            NDArray[Any, LongDouble]
            NDArray[Any, LongFloat]
            NDArray[Any, ComplexFloating]
            NDArray[Any, Complex64]
            NDArray[Any, Complex128]
            NDArray[Any, CSingle]
            NDArray[Any, SingleComplex]
            NDArray[Any, CDouble]
            NDArray[Any, Complex]
            NDArray[Any, CFloat]
            NDArray[Any, CLongDouble]
            NDArray[Any, CLongFloat]
            NDArray[Any, LongComplex]
            NDArray[Any, Flexible]
            NDArray[Any, Void]
            NDArray[Any, Void0]
            NDArray[Any, Character]
            NDArray[Any, Bytes]
            NDArray[Any, String]
            NDArray[Any, Bytes0]
            NDArray[Any, Unicode]
            NDArray[Any, Str0]
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:312: AssertionError
__________________________________________________________________ MyPyTest.test_mypy_accepts_numpy_types __________________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_numpy_types>

    def test_mypy_accepts_numpy_types(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            from nptyping import NDArray
            import numpy as np


            NDArray[Any, np.dtype[np.int_]]
            NDArray[Any, np.dtype[np.float_]]
            NDArray[Any, np.dtype[np.uint8]]
            NDArray[Any, np.dtype[np.bool_]]
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:134: AssertionError
____________________________________________________________ MyPyTest.test_mypy_accepts_recarray_with_structure ____________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_accepts_recarray_with_structure>

    def test_mypy_accepts_recarray_with_structure(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            from nptyping import RecArray, Structure


            RecArray[Any, Structure["x: Float, y: Int"]]
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:117: AssertionError
___________________________________________________ MyPyTest.test_mypy_disapproves_ndarray_with_wrong_function_arguments ___________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_disapproves_ndarray_with_wrong_function_arguments>

    def test_mypy_disapproves_ndarray_with_wrong_function_arguments(self):
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            import numpy as np
            from nptyping import NDArray, Shape


            def func(_: NDArray[Shape["2, 2"], Any]) -> None:
                ...


            func("Not an array...")
        """
        )

        self.assertIn('Argument 1 to "func" has incompatible type "str"', stdout)
        self.assertIn('expected "ndarray[Any, Any]"', stdout)
>       self.assertIn("Found 1 error in 1 file", stdout)
E       AssertionError: 'Found 1 error in 1 file' not found in 'nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]\nnptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment\n/tmp/tmpmb3qsf1a/test_file.py:10: error: Argument 1 to "func" has incompatible type "str"; expected "ndarray[Any, Any]"  [arg-type]\nFound 2 errors in 2 files (checked 1 source file)\n'

tests/test_mypy.py:72: AssertionError
_______________________________________________________________ MyPyTest.test_mypy_knows_of_ndarray_methods ________________________________________________________________

self = <tests.test_mypy.MyPyTest testMethod=test_mypy_knows_of_ndarray_methods>

    def test_mypy_knows_of_ndarray_methods(self):
        # If MyPy knows of some arbitrary ndarray methods, we can assume that
        # code completion works.
        exit_code, stdout, stderr = _check_mypy_on_code(
            """
            from typing import Any
            from nptyping import NDArray


            arr: NDArray[Any, Any]
            arr.shape
            arr.size
            arr.sort
            arr.squeeze
            arr.transpose
        """
        )

>       self.assertEqual(0, exit_code, stdout)
E       AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  [misc]
E       nptyping/structure.pyi:37: note: Error code "misc" not covered by "type: ignore" comment
E       Found 1 error in 1 file (checked 1 source file)

tests/test_mypy.py:171: AssertionError
_________________________________________________________________ WheelTest.test_wheel_is_built_correctly __________________________________________________________________

self = <tests.test_wheel.WheelTest testMethod=test_wheel_is_built_correctly>

    def test_wheel_is_built_correctly(self):
        with working_dir(_ROOT):
>           subprocess.check_output(f"{sys.executable} -m invoke wheel", shell=True)

tests/test_wheel.py:83:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib64/python3.8/subprocess.py:415: in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

input = None, capture_output = False, timeout = None, check = True, popenargs = ('/usr/bin/python3 -m invoke wheel',), kwargs = {'shell': True, 'stdout': -1}
process = <subprocess.Popen object at 0x7fe71e6e7af0>, stdout = b'', stderr = None, retcode = 1

    def run(*popenargs,
            input=None, capture_output=False, timeout=None, check=False, **kwargs):
        """Run command with arguments and return a CompletedProcess instance.

        The returned instance will have attributes args, returncode, stdout and
        stderr. By default, stdout and stderr are not captured, and those attributes
        will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.

        If check is True and the exit code was non-zero, it raises a
        CalledProcessError. The CalledProcessError object will have the return code
        in the returncode attribute, and output & stderr attributes if those streams
        were captured.

        If timeout is given, and the process takes too long, a TimeoutExpired
        exception will be raised.

        There is an optional argument "input", allowing you to
        pass bytes or a string to the subprocess's stdin.  If you use this argument
        you may not also use the Popen constructor's "stdin" argument, as
        it will be used internally.

        By default, all communication is in bytes, and therefore any "input" should
        be bytes, and the stdout and stderr will be bytes. If in text mode, any
        "input" should be a string, and stdout and stderr will be strings decoded
        according to locale encoding, or by "encoding" if set. Text mode is
        triggered by setting any of text, encoding, errors or universal_newlines.

        The other arguments are the same as for the Popen constructor.
        """
        if input is not None:
            if kwargs.get('stdin') is not None:
                raise ValueError('stdin and input arguments may not both be used.')
            kwargs['stdin'] = PIPE

        if capture_output:
            if kwargs.get('stdout') is not None or kwargs.get('stderr') is not None:
                raise ValueError('stdout and stderr arguments may not be used '
                                 'with capture_output.')
            kwargs['stdout'] = PIPE
            kwargs['stderr'] = PIPE

        with Popen(*popenargs, **kwargs) as process:
            try:
                stdout, stderr = process.communicate(input, timeout=timeout)
            except TimeoutExpired as exc:
                process.kill()
                if _mswindows:
                    # Windows accumulates the output in a single blocking
                    # read() call run on child threads, with the timeout
                    # being done in a join() on those threads.  communicate()
                    # _after_ kill() is required to collect that and add it
                    # to the exception.
                    exc.stdout, exc.stderr = process.communicate()
                else:
                    # POSIX _communicate already populated the output so
                    # far into the TimeoutExpired exception.
                    process.wait()
                raise
            except:  # Including KeyboardInterrupt, communicate handled that.
                process.kill()
                # We don't call process.wait() as .__exit__ does that for us.
                raise
            retcode = process.poll()
            if check and retcode:
>               raise CalledProcessError(retcode, process.args,
                                         output=stdout, stderr=stderr)
E               subprocess.CalledProcessError: Command '/usr/bin/python3 -m invoke wheel' returned non-zero exit status 1.

/usr/lib64/python3.8/subprocess.py:516: CalledProcessError
--------------------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------------------
/usr/bin/python3: No module named invoke
============================================================================= warnings summary =============================================================================
../../../../../usr/lib64/python3.8/unittest/loader.py:66
  /usr/lib64/python3.8/unittest/loader.py:66: PytestCollectionWarning: cannot collect test class 'TestLoader' because it has a __init__ constructor (from: tests/test_wheel.py)
    class TestLoader(object):

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
========================================================================= short test summary info ==========================================================================
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_ndarray_with_any - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dty...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_ndarray_with_shape - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "d...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_ndarray_with_structure - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final clas...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_ndarrays_as_function_arguments - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from fi...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_ndarrays_as_variable_hints - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final ...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_nptyping_types - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_numpy_types - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dtype"  ...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_accepts_recarray_with_structure - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final cla...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_disapproves_ndarray_with_wrong_function_arguments - AssertionError: 'Found 1 error in 1 file' not found in 'nptyping/struc...
FAILED tests/test_mypy.py::MyPyTest::test_mypy_knows_of_ndarray_methods - AssertionError: 0 != 1 : nptyping/structure.pyi:37: error: Cannot inherit from final class "dty...
FAILED tests/test_wheel.py::WheelTest::test_wheel_is_built_correctly - subprocess.CalledProcessError: Command '/usr/bin/python3 -m invoke wheel' returned non-zero exit s...
================================================================ 11 failed, 80 passed, 1 warning in 41.36s =================================================================

Here is list of installed modules in build env

Package           Version
----------------- --------------
appdirs           1.4.4
attrs             22.1.0
beartype          0.10.4
Brlapi            0.8.3
build             0.8.0
codespell         2.1.0
cssselect         1.1.0
distro            1.7.0
extras            1.0.0
fixtures          4.0.0
gpg               1.17.1-unknown
iniconfig         1.1.1
libcomps          0.1.18
louis             3.22.0
lxml              4.9.1
mypy              0.971
mypy-extensions   0.4.3
nodeenv           1.7.0
numpy             1.23.1
packaging         21.3
pbr               5.9.0
pep517            0.12.0
pip               22.2.1
pluggy            1.0.0
py                1.11.0
PyGObject         3.42.2
pyparsing         3.0.9
pyright           1.1.268
pytest            7.1.2
python-dateutil   2.8.2
rpm               4.17.0
scour             0.38.2
setuptools        65.3.0
six               1.16.0
testtools         2.5.0
tomli             2.0.1
typeguard         2.13.3
typing_extensions 4.2.0
wheel             0.37.1

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 27 (10 by maintainers)

Most upvoted comments

Tag pattern is has been changed from v<version> to <version>. Mistake or from now now it will be like that? My auomation don’t care about pattern as long as it is fixed 😄

Thank you for testing (so quickly)! I will look into this.

Do you have any plans to update for latest numpy?🤔

Yes I do plan to find a patch for this, hopefully in the coming days.

Just in case … so in your opinion those fails are caused by numpy?🤔

At least most of them are caused by numpy marking dtype as final in 1.23.1 (that was not final in 1.22.4), which some type of nptyping inherits from, which causes mypy to complain, which causes those tests to fail.