- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 33.3k
 
Open
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
I have a big project that uses dataclasses and compiles the code with mypyc for better speed.
I've noticed this exception, when running compiled code:
Here's the smallest repro:
import dataclasses
@dataclasses.dataclass(slots=True, frozen=True)
class User:
    wrapper: 'type[list[int]]'
print(User, getattr(User, '__module__', None))With regular python it runs correctly:
» python ex.py
<class '__main__.User'> __main__
When compiled:
» mypyc ex.py && python -c 'import ex'
copying build/lib.macosx-15.6-arm64-cpython-313/ex.cpython-313-darwin.so -> 
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    import ex
  File "ex.py", line 4, in <module>
    class User:
  File "/Users/sobolev/.pyenv/versions/3.13.7/lib/python3.13/dataclasses.py", line 1295, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/Users/sobolev/.pyenv/versions/3.13.7/lib/python3.13/dataclasses.py", line 997, in _process_class
    and _is_type(type, cls, dataclasses, dataclasses.KW_ONLY,
        ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                 _is_kw_only))):
                 ^^^^^^^^^^^^
  File "/Users/sobolev/.pyenv/versions/3.13.7/lib/python3.13/dataclasses.py", line 757, in _is_type
    ns = sys.modules.get(cls.__module__).__dict__
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute '__dict__'. Did you mean: '__dir__'?I propose to fix this on dataclasses's side, because fix is quite trivial.
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
