Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
A similar issue to #96151. ericvsmith mentioned this is worth opening an issue for in #98143 (comment)
dataclasses uses variables with single underscore names as part of its implementation. This can cause interesting errors, for example:
from dataclasses import dataclass, field
@dataclass
class X:
x: int = field(default_factory=lambda: 111)
_dflt_x: int = field(default_factory=lambda: 222)
X() # TypeError: '_HAS_DEFAULT_FACTORY_CLASS' object is not callableThe fix is simple: prefix all of these things with __dataclass_, to make name collisions more obviously the user's fault. We already do this for e.g. __dataclass_self__ in the implementation.
Linked PRs
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
pythongh-98886: Fix issues with fields with special underscore names
Merge branch 'main' into pythongh-98886
Merge branch 'main' into pythongh-98886
gh-98886: Fix issues with dataclass fields with special underscore na…
pythongh-98886: Fix issues with dataclass fields with special undersc…
pythongh-98886: Fix issues with dataclass fields with special undersc…