GeezerVison is showing github.com — Dataclass takes no arguments in a subinterpreter in 3.12 · Issue #110279 · python/cpython
Dataclass takes no arguments in a subinterpreter in 3.12 #110279DescriptionBug 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:
#include <stdio.h>
#include <Python.h>
const char* code = "\n\
from dataclasses import dataclass\n\
\n\
@dataclass\n\
class MyClass:\n\
id: str\n\
\n\
c = MyClass(id='abc')\n\
print(c)\n\
";
int main(int argc, char** argv) {
Py_InitializeEx(0);
printf("Python version: ");
fflush(stdout);
PyRun_SimpleString("import sys; print(sys.version)");
PyThreadState* main_thread = PyThreadState_Get();
printf("In main interpreter:\n");
PyRun_SimpleString(code);
PyThreadState* interpreter_thread = Py_NewInterpreter();
printf("\nIn subinterpreter:\n");
PyRun_SimpleString(code);
Py_EndInterpreter(interpreter_thread);
PyThreadState_Swap(main_thread);
Py_Finalize();
return 0;
}
Compiled with gcc -o py_dataclass py_dataclass.c -I /usr/include/python3.11 -lpython3.11 I get the expected:
Python version: 3.11.5 (main, Aug 25 2023, 13:19:50) [GCC 11.4.0]
In main interpreter:
MyClass(id='abc')
In subinterpreter:
MyClass(id='abc')
Compiled with gcc -o py_dataclass py_dataclass.c -I /usr/include/python3.12 -lpython3.12 I get:
Python version: 3.12.0 (main, Oct 2 2023, 15:04:50) [GCC 11.4.0]
In main interpreter:
MyClass(id='abc')
In subinterpreter:
Traceback (most recent call last):
File "<string>", line 8, in <module>
TypeError: MyClass() takes no arguments
This is using the python3.11-dev and python3.12-dev packages 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
from dataclasses import dataclass
@dataclass
class MyClass:
id: str
c = MyClass(id='abc')
print(c)
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 Activitypeterebden commented 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) AA-Turner commented on Oct 3, 2023 ericsnowcurrently commented on Oct 4, 2023 ericsnowcurrently commented on Oct 4, 2023 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)
""")peterebden commented on Oct 4, 2023 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). ericvsmith commented on Oct 4, 2023 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. graingert commented on Oct 4, 2023 bisected to ba65a06 on 3.12
looks like it was fixed again on main in b72947a Reacted by Eric Snow, Matt Thompson, Tushar Sadhwani, Eric V. Smith, Thomas Grainger and An Long ericvsmith commented on Oct 4, 2023 Do you know if that made it to the 3.12 branch (so would be in 3.12.1)? ericsnowcurrently commented on Oct 4, 2023 graingert commented on Oct 4, 2023 I just tried e658413 (the head of 3.12) and I still reproduce the failure anthonyfk commented on Nov 3, 2023 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. ericsnowcurrently commented on Nov 28, 2023 I've merged the backport fix. Could someone verify whether or not this is fixed now. Thanks! thierryba commented on Dec 6, 2023 @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. uckelman commented on Dec 8, 2023 thierryba commented on Dec 8, 2023 Does anyone know if this fix in included in 3.12.1? ericsnowcurrently commented on Dec 8, 2023 The fix is indeed part of 3.12.1. peterebden commented on Dec 13, 2023 Thanks, also fixed for me! uckelman commented on Dec 19, 2023 The fix is in Fedora 39 as of a day or two ago.
MetadataMetadataStatusShow more project fields
DevelopmentNo branches or pull requestsIssue actions
|