GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #110279

New issue
Copy link
New issue
Copy link
Closed
Closed
Dataclass takes no arguments in a subinterpreter in 3.12#110279
Copy link
Assignees
ericsnowcurrently
Labels
3.12only security fixesonly security fixestopic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@peterebden
peterebden
opened on Oct 3, 2023
Issue body actions

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:

#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

Activity

  1. peterebden
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Oct 3, 2023
  2. peterebden commented on Oct 3, 2023

    @peterebden
    peterebden
    on Oct 3, 2023
    Author
    More actions

    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)
  3. AlexWaygood
    added
    topic-subinterpreters
    on Oct 3, 2023
  4. github-project-automation
    added this to Subinterpreterson Oct 3, 2023
  5. github-project-automation
    moved this to Todo in Subinterpreterson Oct 3, 2023
  6. AA-Turner
    added
    3.12only security fixesonly security fixes
    3.13only security fixesonly security fixes
    on Oct 3, 2023
  7. AA-Turner commented on Oct 3, 2023

    @AA-Turner
    AA-Turner
    on Oct 3, 2023
    Member
    More actions

    cc: @ericsnowcurrently

  8. ericsnowcurrently commented on Oct 4, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Oct 4, 2023
    Member
    More actions

    Any ideas, @ericvsmith?

  9. ericsnowcurrently commented on Oct 4, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Oct 4, 2023
    Member
    More actions

    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)
        """)
  10. peterebden commented on Oct 4, 2023

    @peterebden
    peterebden
    on Oct 4, 2023
    Author
    More actions

    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).

  11. ericvsmith commented on Oct 4, 2023

    @ericvsmith
    ericvsmith
    on Oct 4, 2023
    Member
    More actions

    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.

  12. AlexWaygood
    removed
    3.13only security fixesonly security fixes
    on Oct 4, 2023
  13. graingert commented on Oct 4, 2023

    @graingert
    graingert
    on Oct 4, 2023
    Contributor
    More actions

    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
  14. ericsnowcurrently
    self-assigned this
    on Oct 4, 2023
  15. ericvsmith commented on Oct 4, 2023

    @ericvsmith
    ericvsmith
    on Oct 4, 2023
    Member
    More actions

    Do you know if that made it to the 3.12 branch (so would be in 3.12.1)?

  16. ericsnowcurrently commented on Oct 4, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Oct 4, 2023
    Member
    More actions

    I had decided not to backport it. Clearly I need to revisit that decision. 😄

  17. graingert commented on Oct 4, 2023

    @graingert
    graingert
    on Oct 4, 2023
    Contributor
    More actions

    I just tried e658413 (the head of 3.12) and I still reproduce the failure

  18. anthonyfk commented on Nov 3, 2023

    @anthonyfk
    anthonyfk
    on Nov 3, 2023
    More actions

    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 Uckelman
  19. ericsnowcurrently commented on Nov 28, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Nov 28, 2023
    Member
    More actions

    I've merged the backport fix. Could someone verify whether or not this is fixed now. Thanks!

  20. thierryba commented on Dec 6, 2023

    @thierryba
    thierryba
    on Dec 6, 2023
    More actions

    @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.

  21. uckelman commented on Dec 8, 2023

    @uckelman
    uckelman
    on Dec 8, 2023
    More actions

    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.

  22. thierryba commented on Dec 8, 2023

    @thierryba
    thierryba
    on Dec 8, 2023
    More actions

    Does anyone know if this fix in included in 3.12.1?

  23. ericsnowcurrently commented on Dec 8, 2023

    @ericsnowcurrently
    ericsnowcurrently
    on Dec 8, 2023
    Member
    More actions

    The fix is indeed part of 3.12.1.

  24. ericsnowcurrently
    closed this as completedon Dec 8, 2023
  25. github-project-automation
    moved this from Todo to Done in Subinterpreterson Dec 8, 2023
  26. peterebden commented on Dec 13, 2023

    @peterebden
    peterebden
    on Dec 13, 2023
    Author
    More actions

    Thanks, also fixed for me!

    Reacted by Eric Snow
  27. uckelman commented on Dec 19, 2023

    @uckelman
    uckelman
    on Dec 19, 2023
    More actions

    The fix is in Fedora 39 as of a day or two ago.

    Reacted by Eric Snow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ericsnowcurrently
    ericsnowcurrently

Labels

3.12only security fixesonly security fixestopic-subinterpreterstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • Subinterpreters
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.