Skip to content

Dataclasses without __init__ no longer work in 3.14.1 due to #137711 #142214

Description

@emontnemery

Bug report

Bug description:

The resolution for #137530, #137711 which was backported to 3.14 and included in 3.14.1, breaks dataclasses without __init__.
Although a dataclass without __init__ doesn't seem that helpful, it doesn't seem to be explicitly forbidden and shouldn't break in a point release.

from dataclasses import dataclass, field

@dataclass(slots=True, init=False)
class MyClass:
    attr: int

    def __new__(cls, attr: int) -> Self:
        self.attr = attr
        return self

Error message:

$ python3 dataclasses_issue.py
Traceback (most recent call last):
  File "/home/erik/dataclasses_issue.py", line 3, in <module>
    @dataclass(slots=True, init=False)
     ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/erik/.pyenv/versions/3.14.1/lib/python3.14/dataclasses.py", line 1426, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
                          frozen, match_args, kw_only, slots,
                          weakref_slot)
  File "/home/erik/.pyenv/versions/3.14.1/lib/python3.14/dataclasses.py", line 1234, in _process_class
    cls = _add_slots(cls, frozen, weakref_slot, fields)
  File "/home/erik/.pyenv/versions/3.14.1/lib/python3.14/dataclasses.py", line 1401, in _add_slots
    init_annotate = newcls.__init__.__annotate__
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'wrapper_descriptor' object has no attribute '__annotate__'. Did you mean: '__getstate__'?

CPython versions tested on:

3.14.1

Operating systems tested on:

Linux

Linked PRs

Activity

  1. changed the title [-]Dataclasses without __init__ no longer work due to #137711[/-] [+]Dataclasses without __init__ no longer work in 3.14.1 due to #137711[/+] on Dec 3, 2025
  2. dpinol commented on Dec 3, 2025

    @dpinol

    as an example, it breaks networkx 3.6

      File "/usr/local/lib/python3.14/site-packages/networkx/utils/configs.py", line 8, in <module>
        @dataclass(init=False, eq=False, slots=True, kw_only=True, match_args=False)
         ~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/usr/local/lib/python3.14/dataclasses.py", line 1426, 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 1234, in _process_class
        cls = _add_slots(cls, frozen, weakref_slot, fields)
      File "/usr/local/lib/python3.14/dataclasses.py", line 1401, in _add_slots
        init_annotate = newcls.__init__.__annotate__
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AttributeError: 'wrapper_descriptor' object has no attribute '__annotate__'. Did you mean: '__getstate__'?
  3. Giuzzilla commented on Dec 3, 2025

    @Giuzzilla

    Python 3.14.1 is breaking my sqlalchemy-based project as well, seems related to the issue/dataclasses, stacktrace:

    mypackage/mymodel.py:109: in <module>
        class MyModel(Base, kw_only=True):
    .venv/lib/python3.14/site-packages/sqlalchemy/orm/decl_api.py:626: in __init_subclass__
        super().__init_subclass__(**kw)
    .venv/lib/python3.14/site-packages/sqlalchemy/orm/decl_api.py:846: in __init_subclass__
        _as_declarative(cls._sa_registry, cls, cls.__dict__)
    .venv/lib/python3.14/site-packages/sqlalchemy/orm/decl_base.py:245: in _as_declarative
        return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    .venv/lib/python3.14/site-packages/sqlalchemy/orm/decl_base.py:326: in setup_mapping
        return _ClassScanMapperConfig(
    .venv/lib/python3.14/site-packages/sqlalchemy/orm/decl_base.py:564: in __init__
        self._setup_dataclasses_transforms()
    .venv/lib/python3.14/site-packages/sqlalchemy/orm/decl_base.py:1171: in _setup_dataclasses_transforms
        self._apply_dataclasses_to_any_class(
    .venv/lib/python3.14/site-packages/sqlalchemy/orm/decl_base.py:1227: in _apply_dataclasses_to_any_class
        dataclass_callable(  # type: ignore[call-overload]
    /usr/local/lib/python3.14/dataclasses.py:1436: in dataclass
        return wrap(cls)
               ^^^^^^^^^
    /usr/local/lib/python3.14/dataclasses.py:1426: in wrap
        return _process_class(cls, init, repr, eq, order, unsafe_hash,
    /usr/local/lib/python3.14/dataclasses.py:1217: in _process_class
        text_sig = str(inspect.signature(
    /usr/local/lib/python3.14/inspect.py:3321: in signature
        return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
    /usr/local/lib/python3.14/inspect.py:3036: in from_callable
        return _signature_from_callable(obj, sigcls=cls,
    /usr/local/lib/python3.14/inspect.py:2557: in _signature_from_callable
        return _get_signature_of(init)
               ^^^^^^^^^^^^^^^^^^^^^^^
    /usr/local/lib/python3.14/inspect.py:2440: in _signature_from_callable
        sig = _get_signature_of(obj.__func__)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /usr/local/lib/python3.14/inspect.py:2511: in _signature_from_callable
        return _signature_from_function(sigcls, obj,
    /usr/local/lib/python3.14/inspect.py:2334: in _signature_from_function
        annotations = get_annotations(func, globals=globals, locals=locals, eval_str=eval_str,
    /usr/local/lib/python3.14/annotationlib.py:973: in get_annotations
        ann = _get_and_call_annotate(obj, format)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /usr/local/lib/python3.14/annotationlib.py:1112: in _get_and_call_annotate
        ann = call_annotate_function(annotate, format, owner=obj)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /usr/local/lib/python3.14/annotationlib.py:711: in call_annotate_function
        return annotate(format)
               ^^^^^^^^^^^^^^^^
    /usr/local/lib/python3.14/dataclasses.py:553: in __annotate__
        new_annotations[k] = cls_annotations[k]
                             ^^^^^^^^^^^^^^^^^^
    E   KeyError: 'my_field'
  4. pareshjoshij commented on Dec 3, 2025

    @pareshjoshij
    Contributor

    Looks like we're seeing two different side effects from the recent annotation updates.

    1 The NetworkX crash: It seems init=False exposes object.init (a wrapper descriptor), which naturally lacks annotate.

    2 The SQLAlchemy KeyError: It looks like the code assumes every field must exist in cls_annotations. That assumption might be too strict for dynamic classes where attributes are injected.

    I suspect adding guards in both spots to handle missing attributes/keys would fix this?

  5. pareshjoshij commented on Dec 3, 2025

    @pareshjoshij
    Contributor

    @epenet that link speaks volumes.

    The fact that they had to rush that merge to unblock CI—even skipping the documentation steps you suggested—really confirms how severe the instability is for downstream users.

  6. changed the title [-]Dataclasses without __init__ no longer work in 3.14.1 due to #137711[/-] [+]Dataclasses without `__init__` no longer work in 3.14.1 due to #137711[/+] on Dec 3, 2025
  7. added
    stdlibStandard Library Python modules in the Lib/ directory
    3.14bugs and security fixes
    3.15bugs and security fixes
    on Dec 3, 2025
  8. 20 remaining items

  9. added a commit that references this issue on Dec 5, 2025
  10. hugovk commented on Dec 5, 2025

    @hugovk
    Member

    Thanks all, merged and backported, will hopefully be released in 3.14.2 today.

  11. added a commit that references this issue on Dec 5, 2025
  12. added a commit that references this issue on Dec 6, 2025
  13. added a commit that references this issue on Dec 7, 2025
  14. added a commit that references this issue on Dec 8, 2025
  15. wimglenn commented on Dec 10, 2025

    @wimglenn
    Contributor

    I was thinking, could there be something in the CPython release process for maintenance releases which sanity checks that an assortment of heavily used libraries such as networkx and sqlalchemy can successfully import?

    That sounds like some low hanging fruit, and something easy to automate for catching potentially disruptive issues before the release is published and gets picked up by various GitHub actions. I had some uv python install 3.14 in .github/workflows which automatically picked up the micro bump on Dec 2 and CIs got trashed (fortunately the fix was trivial just pinning it to 3.14.0 in the workflow yaml).

  16. hugovk commented on Dec 10, 2025

    @hugovk
    Member

    It's been considered in the past (for example, PEP 608 / https://discuss.python.org/t/rejected-rfc-pep-608-coordinated-python-release/2539 six years ago) but iirc rejected due to the amount of work and diversity of test setups.

    I suggest opening a new discussion, though, if you think things are better now to retry it.

  17. zzzeek commented on Dec 10, 2025

    @zzzeek

    a coordinated release seems a little heavy handed, but there's no reason people (anyone, python devs, OSS authors, interested parties) can't run CIs (like a series of github actions somehwere) that test the Python main branch against some series of OSS libraries, and just report github issues for failures that are observed.

    CIs like these can be burdensome as when you are tracking the "main" of another project, there's often unrelated problems that get checked into main. plus you have to stay on top of deployment / test runner changes in the project (though cPython is extremely good at staying exactly the same in my experience).

  18. encukou commented on Dec 10, 2025

    @encukou
    Member

    I've been thinking whether the 3.x.1 release needs a RC period, given that all fixes from the long 3.x.0 RC period land there.

  19. hugovk commented on Feb 2, 2026

    @hugovk
    Member

    Reported @stomde to GitHub.

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

    3.14bugs and security fixes3.15bugs and security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directorytopic-dataclassestopic-typingtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions