ericvsmith / dataclasses

Apache License 2.0
584 stars 53 forks source link

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

Open anthrotype opened 3 years ago

anthrotype commented 3 years ago

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