alexmojaki / pure_eval

Safely evaluate AST nodes without side effects
MIT License
42 stars 13 forks source link

Test failures with PyPy3.10 7.3.13 #15

Open mgorny opened 7 months ago

mgorny commented 7 months ago

When running the test suite against PyPy3.10, I'm getting the following failures:

$ tox -e pypy310
.pkg: _optional_hooks> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: get_requires_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: prepare_metadata_for_build_wheel> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
.pkg: build_sdist> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
pypy310: install_package_deps> python -I -m pip install pytest
pypy310: install_package> python -I -m pip install --force-reinstall --no-deps /tmp/pure_eval/.tox/.tmp/package/2/pure_eval-0.2.3.dev2+gc6958c1.tar.gz
pypy310: commands[0]> pytest
========================================================= test session starts =========================================================
platform linux -- Python 3.10.13[pypy-7.3.13-final], pytest-7.4.3, pluggy-1.3.0
cachedir: .tox/pypy310/.pytest_cache
rootdir: /tmp/pure_eval
collected 47 items                                                                                                                    

tests/test_core.py .................                                                                                            [ 36%]
tests/test_getattr_static.py ....F..................                                                                            [ 85%]
tests/test_utils.py ...F...                                                                                                     [100%]

============================================================== FAILURES ===============================================================
______________________________________________ TestGetattrStatic.test_custom_object_dict ______________________________________________

self = <tests.test_getattr_static.TestGetattrStatic testMethod=test_custom_object_dict>

    def test_custom_object_dict(self):
        class Custom(dict):
            def get(self, key, default=None):
                return 1 / 0

            __getitem__ = get

        class Foo(object):
            a = 3

        foo = Foo()
        foo.__dict__ = Custom()
        foo.x = 5
>       self.assert_getattr(foo, 'a')

tests/test_getattr_static.py:257: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/test_getattr_static.py:15: in assert_getattr
    getattr(thing, attr),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = {'x': 5}, key = 'a', default = None

    def get(self, key, default=None):
>       return 1 / 0
E       ZeroDivisionError: division by zero

tests/test_getattr_static.py:247: ZeroDivisionError
_______________________________________________________ test_safe_name_samples ________________________________________________________

    def test_safe_name_samples():
        for name, f in {**safe_name_samples, **typing_annotation_samples}.items():
>           assert name == safe_name(f)
E           AssertionError: assert '__mul__' == '__rmul__'
E             - __rmul__
E             ?   -
E             + __mul__

tests/test_utils.py:80: AssertionError
========================================================== warnings summary ===========================================================
tests/test_core.py::test_cannot_subscript[[1][:,:]]
  <string>:1: SyntaxWarning: list indices must be integers or slices, not tuple; perhaps you missed a comma?

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
======================================================= short test summary info =======================================================
FAILED tests/test_getattr_static.py::TestGetattrStatic::test_custom_object_dict - ZeroDivisionError: division by zero
FAILED tests/test_utils.py::test_safe_name_samples - AssertionError: assert '__mul__' == '__rmul__'
=============================================== 2 failed, 45 passed, 1 warning in 3.60s ===============================================
pypy310: exit 1 (3.96 seconds) /tmp/pure_eval> pytest pid=424082
.pkg: _exit> python /usr/lib/python3.12/site-packages/pyproject_api/_backend.py True setuptools.build_meta
  pypy310: FAIL code 1 (12.59=setup[8.63]+cmd[3.96] seconds)
  evaluation failed :( (12.66 seconds)

CC @mattip, perhaps PyPy is doing something weird here.

mattip commented 7 months ago

I think this is a documented difference, see https://doc.pypy.org/en/latest/cpython_differences.html#subclasses-of-built-in-types

alexmojaki commented 7 months ago

I think this is a documented difference, see https://doc.pypy.org/en/latest/cpython_differences.html#subclasses-of-built-in-types

This does explain the test_custom_object_dict failure.

The test_safe_name_samples failure is coming from the fact that list.__mul__ is list.__rmul__ so list.__mul__.__name__ == '__rmul__' which isn't crazy or super important but feels a bit odd at least.

Fixing that leads to another error which seems less justified:

>>>> dict.__dict__['fromkeys'].__name__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'classmethod' object has no attribute '__name__'. Did you mean: '__ne__'?