-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
Closed
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-dataclassestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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 selfError 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
Giuzzilla, edenhaus, SamWarden, basnijholt, ADBond and 7 more
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-dataclassestopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
Status
Done