Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fields with single underscore names can mess up dataclasses #98886

Closed
Assignees
hauntsaninja
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@hauntsaninja

Description

@hauntsaninja

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:

fromdataclassesimportdataclass,field@dataclassclassX:x:int=field(default_factory=lambda:111)_dflt_x:int=field(default_factory=lambda:222)X()# TypeError: '_HAS_DEFAULT_FACTORY_CLASS' object is not callable

The 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/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp