Sitelet https://web.archive.org/web/20250524181127/https://github.com/python/cpython/issues/99713
Skip to content

Update __dataclass_params__ to track actual changes made by decorator #99713

Open
@ethanfurman

Description

@ethanfurman

Several of the options available via the dataclass decorator, such as repr, hash, and eq, are ignored if the corresponding methods are already in the class being decorated; however, they still have their default value of True. This makes it difficult, if not impossible, to discern whether a dataclass' special method was given by dataclass or if the user wrote it.

As an example of the introspection concern, Enum uses __dataclass_params__.repr to decide if it should use a dataclass-specific repr, or use the dataclass' repr. Without this enhancement, the user has to both specify @dataclass(repr=False) and include their new __repr__ method, instead of just including the new __repr__ and having dataclass automatically set __dataclass_params__.repr to False.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions