Closed
Description
After being a bit late with Python 3.13, I figured to start testing 3.14 early this time.
With Python 3.14.0a1
the following fails:
# native.py
from typing import Any
def dec(x: Any) -> Any:
return x
@dec
class D:
x: int
class E(D):
y: int
# driver.py
from native import D, E
import pickle
assert not hasattr(D, '__mypyc_attrs__')
assert E.__mypyc_attrs__ == ('y', '__dict__')
e = E()
e.x = 10
e.y = 20
assert e.__getstate__() == {'y': 20, '__dict__': {'x': 10}}
e2 = pickle.loads(pickle.dumps(e))
assert e is not e2 and e.x == e2.x and e.y == e2.y
rm -rf build
rm *.so
python3.14 -m mypyc native.py
python3.14 -c 'import driver.py'
The error message
$ python -c "import driver.py"
Traceback (most recent call last):
File "<string>", line 1, in <module>
import driver.py
File ".../driver.py", line 14, in <module>
assert e is not e2 and e.x == e2.x and e.y == e2.y
^^^^
AttributeError: 'E' object has no attribute 'x'
I bisected this to python/cpython#123192 upstream.
--
This is also part of the mypyc test suite
pytest -n0 mypyc/test/test_run.py::TestRun::run-classes.test::testPickling
Metadata
Metadata
Assignees
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
[-]Pickle test failure with Python 3.14a1[/-][+]Pickle test failure with Python 3.14.0a1[/+][-]Pickle test failure with Python 3.14.0a1[/-][+][mypyc] Pickle test failure with Python 3.14.0a1[/+]hauntsaninja commentedon Oct 17, 2024
I suspect it's something funky when calling
PyObject_SetAttr(obj, "__dict__", {"x": 10})
, which is what mypyc will do here when unpicklingWith a debug Python build you also get a segfault following the AttributeError:
In lldb:
cdce8p commentedon Nov 20, 2024
Still an issue with
3.14.0a2
cdce8p commentedon Dec 18, 2024
Still an issue with
3.14.0a3
as well.Edit: And with
3.14.0a4
too.cdce8p commentedon Feb 1, 2025
A possible workaround could be to disable the
Py_TPFLAGS_INLINE_VALUES
here:mypy/mypyc/lib-rt/misc_ops.c
Lines 299 to 304 in f44a60d
With that the test case passes again (and no other test is failing because of it). However, I'm unsure that's the correct solution. With python/cpython#123192
Py_TPFLAGS_INLINE_VALUES
is automatically set fortype->tp_itemsize == 0
which is the case here.cdce8p commentedon Feb 1, 2025
From what I can tell the
testPickling
case also had issues when adding support for 3.12./CC @JukkaL
cdce8p commentedon May 30, 2025
This was fixed in python/cpython#134859 which will be included in Python 3.14.0b3.