Skip to content

dataclasses.replace raises exception if InitVars with default argument is not provided #164

@anthrotype

Description

@anthrotype

This is the same issue as https://bugs.python.org/issue36470, I open a new issue here for greater visibility.

Basically if one has a dataclass which defines an InitVars with a default value, and then uses dataclasses.replace on an instance without passing the init var as parameter to replace, a ValueError: InitVar '...' must be specified with replace() error is raised.

This is bad, because the InitVar already defines its default value, there's no need to expect a value when using replace().
It makes it impossible to use replace() at the same time as default InitVars.

The fix is trivial and there are already two PRs to upstream cpython dataclasses.

python/cpython#17441
python/cpython#20867

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions