enthought / apptools

Other
37 stars 24 forks source link

Tests fail with Python 3.11: AttributeError: 'NoneType' object has no attribute 'pop' #325

Closed s3v- closed 1 year ago

s3v- commented 1 year ago

Some tests start failing with Python 3.11. See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1027503

> ======================================================================
> ERROR: Test the get_version function.
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/tests/test_version_registry.py", line 69, in test_get_version
>     state = state_pickler.get_state(c)
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 996, in get_state
>     s = dumps(obj)
>         ^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 968, in dumps
>     return StatePickler().dumps(value)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 308, in dumps
>     return pickle.dumps(self._do(value))
>                         ^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 358, in _do
>     return self._do_instance(obj)
>            ^^^^^^^^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 403, in _do_instance
>     state.pop("__traits_version__", None)
>     ^^^^^^^^^
> AttributeError: 'NoneType' object has no attribute 'pop'
> 
> ======================================================================
> ERROR: Test if update method calls the handlers in order.
> ----------------------------------------------------------------------
> Traceback (most recent call last):
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/tests/test_version_registry.py", line 111, in test_update
>     state = state_pickler.get_state(c)
>             ^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 996, in get_state
>     s = dumps(obj)
>         ^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 968, in dumps
>     return StatePickler().dumps(value)
>            ^^^^^^^^^^^^^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 308, in dumps
>     return pickle.dumps(self._do(value))
>                         ^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 358, in _do
>     return self._do_instance(obj)
>            ^^^^^^^^^^^^^^^^^^^^^^
>   File "/<<PKGBUILDDIR>>/.pybuild/cpython3_3.11_apptools/build/apptools/persistence/state_pickler.py", line 403, in _do_instance
>     state.pop("__traits_version__", None)
>     ^^^^^^^^^
> AttributeError: 'NoneType' object has no attribute 'pop'
> 
> ----------------------------------------------------------------------
> Ran 355 tests in 1.754s
> 
> FAILED (errors=2)

Please note that every pyckable object has __getstate method in Python 3.11 [https://docs.python.org/3/library/pickle.html#object.\_\_getstate\_\_](https://docs.python.org/3/library/pickle.html#object.getstate__) As a consequence, "else" statement is never hitted in this cycle: https://github.com/enthought/apptools/blob/127fe9fe293c49c8a6626101bc3cf0684e163bf8/apptools/persistence/state_pickler.py#L395-L401

Kind Regards

emollier commented 1 year ago

Hi, I added the following ~fix~ workaround for python3.11 on Debian salsa; also uploaded.

Hope this helps, Étienne.

mdickinson commented 1 year ago

Thanks for the report. We're planning some maintenance on apptools in the near-ish future, and that will include getting things back to working on Python 3.11.

mdickinson commented 1 year ago

For reference, the relevant change in CPython was this one: https://github.com/python/cpython/pull/2821