diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2023-10-04 06:20:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-04 06:20:14 (GMT) |
commit | 5b9a3fd6a0ce3c347463e6192a59c15f5fcb0043 (patch) | |
tree | d5eababb628c9a8d66bc5e8386a3add2a843c5c3 /Lib/dataclasses.py | |
parent | bfe7e72522565f828f43c2591fea84a7981ee048 (diff) | |
download | cpython-5b9a3fd6a0ce3c347463e6192a59c15f5fcb0043.zip cpython-5b9a3fd6a0ce3c347463e6192a59c15f5fcb0043.tar.gz cpython-5b9a3fd6a0ce3c347463e6192a59c15f5fcb0043.tar.bz2 |
gh-110273: dataclasses.replace() now raise TypeError for all invalid arguments (GH-110274)
dataclasses.replace() now raises TypeError instead of ValueError if
specify keyword argument for a field declared with init=False or miss keyword
argument for required InitVar field.
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r-- | Lib/dataclasses.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py index 84f8d68..31dc6f8 100644 --- a/Lib/dataclasses.py +++ b/Lib/dataclasses.py @@ -1567,15 +1567,15 @@ def _replace(obj, /, **changes): if not f.init: # Error if this field is specified in changes. if f.name in changes: - raise ValueError(f'field {f.name} is declared with ' - 'init=False, it cannot be specified with ' - 'replace()') + raise TypeError(f'field {f.name} is declared with ' + f'init=False, it cannot be specified with ' + f'replace()') continue if f.name not in changes: if f._field_type is _FIELD_INITVAR and f.default is MISSING: - raise ValueError(f"InitVar {f.name!r} " - 'must be specified with replace()') + raise TypeError(f"InitVar {f.name!r} " + f'must be specified with replace()') changes[f.name] = getattr(obj, f.name) # Create the new object, which calls __init__() and |