dataclasses icon indicating copy to clipboard operation
dataclasses copied to clipboard

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

Open anthrotype opened this issue 4 years ago • 0 comments

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.

https://github.com/python/cpython/pull/17441 https://github.com/python/cpython/pull/20867

anthrotype avatar Jan 29 '21 15:01 anthrotype