Repository navigation
Dataclass takes no arguments in a subinterpreter in 3.12 #110279
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 3, 2023 An interesting datapoint; the following code does work as expected in the subinterpreter:
from dataclasses import dataclass @dataclass class MyClass: id: str @dataclass class MySubClass(MyClass): pass c = MySubClass(id='abc') print(c)
- added3.12only security fixesonly security fixes3.13only security fixesonly security fixes
on Oct 3, 2023 Any ideas, @ericvsmith?
FWIW, it seems to work fine on main. I was able to reproduce the failure on 3.12:
from test.support import interpreters interp = interpreters.create() interp.run("""if True: from dataclasses import dataclass @dataclass class MyClass: id: str c = MyClass(id='abc') print(c) """)
Ah nice, I didn't know that test module was available to try it out in pure Python.
Also working for me at head, same for our internal usage (which is a bit more complex than the reduced example here - there's something else going wrong there which I'm still digging through).
I have no idea what's going on there. I don't have handy access to my dev box right now, but maybe inspecting the signature for
MyClass.__init__will shed some light.Do you know if that made it to the 3.12 branch (so would be in 3.12.1)?
I had decided not to backport it. Clearly I need to revisit that decision. 😄
I just tried e658413 (the head of 3.12) and I still reproduce the failure
For what it's worth, this has broken using Flask in Apache with mod_wsgi, meaning I cannot upgrade to Python 3.12 until this is fixed. So please consider getting this into 3.12.1.
Reacted by Joel UckelmanI've merged the backport fix. Could someone verify whether or not this is fixed now. Thanks!
@ericsnowcurrently if you point me to the patch to try, I can do it. I have the same problems with mod_wsgi in a Django application.
I reported this in Fedora's bug tracker: https://bugzilla.redhat.com/show_bug.cgi?id=2252567
They made a build with the patch; I tested their build and confirmed that Flask apps no longer fail with the patch.
Does anyone know if this fix in included in 3.12.1?
The fix is indeed part of 3.12.1.
Thanks, also fixed for me!
Reacted by Eric SnowThe fix is in Fedora 39 as of a day or two ago.
Reacted by Eric Snow
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Bug report
Bug description:
In 3.12, when I construct an instance of a dataclass in a subinterpreter, I get an "X takes no arguments" error, for cases that work fine in the main interpreter.
A fairly minimal code example:
Compiled with
gcc -o py_dataclass py_dataclass.c -I /usr/include/python3.11 -lpython3.11I get the expected:Compiled with
gcc -o py_dataclass py_dataclass.c -I /usr/include/python3.12 -lpython3.12I get:This is using the
python3.11-devandpython3.12-devpackages from the deadsnakes PPA.I'm a little lost about what the interaction between the subinterpreter and the dataclass is that would cause this. The non-mangled Python code is just
Let me know if there's any more info I can provide!
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
Linux