-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dataclasses.replace raises an exception if InitVar with default argument is not provided. #80651
Comments
I have a snippet below which runs fine on python 3.7.0 but raises a ValueError exception on 3.7.1. I believe it's related to https://bugs.python.org/issue33805. The error: c:\python\lib\dataclasses.py:1219: ValueError The script: from dataclasses import replace, dataclass, InitVar
@dataclass
class Test:
a:int = 1
b:InitVar[int] = None
def __post_init__(self, b):
if b is not None:
self.a = b
if __name__ == '__main__':
t = Test()
t1 = Test(b=5)
assert t1.a == 5
t2 = replace(t1, **{})
print(t2) |
Fixed title |
any updates on this? Would be great if any of the two candidate PRs was merged. It's basically impossible to use replace() with default InitVars.. |
Thanks for the fix! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: