Skip to content

Can't use @dataclass in the script #8279

Open

Description

@crepererum

Problem Description

Using a dataclass like this:

from dataclasses import dataclass

@dataclass
class C:
    x: int

leads to an error like this:

Traceback (most recent call last):                                                       
  File "/script.py", line 200, in <module>                                               
    @dataclass                                                                           
     ^^^^^^^^^                                                                           
  File "/usr/local/lib/python3.14/dataclasses.py", line 1370, in dataclass               
    return wrap(cls)                                                                     
  File "/usr/local/lib/python3.14/dataclasses.py", line 1360, in wrap                    
    return _process_class(cls, init, repr, eq, order, unsafe_hash,                       
                          frozen, match_args, kw_only, slots,                            
                          weakref_slot)                                                  
  File "/usr/local/lib/python3.14/dataclasses.py", line 943, in _process_class           
    globals = sys.modules[cls.__module__].__dict__                                       
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                       
AttributeError: 'object' object has no attribute '__dict__'. Did you mean: '__dir__'?    

This seems to be similar to mkdocs/mkdocs#3141 and demands a similar fix.

A somewhat hacky workaround is to use something like this at the top of your script (this technically sets the wrong module, but still works):

# workaround for dataclass
sys.modules[__name__] = mitmproxy

System Information

Mitmproxy: 12.2.0
Python:    3.14.0
OpenSSL:   OpenSSL 3.5.4 30 Sep 2025
Platform:  Linux-7.0.11-200.fc44.x86_64-x86_64-with-glibc2.41

Checklist

Activity

  1. added
    kind/triage
    on Jun 9, 2026
  2. added a commit that references this issue on Jul 23, 2026
    ad826c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions