summaryrefslogtreecommitdiffstats
path: root/Lib/dataclasses.py
diff options
context:
space:
mode:
authorEric V. Smith <ericvsmith@users.noreply.github.com>2023-08-10 14:39:13 (GMT)
committerGitHub <noreply@github.com>2023-08-10 14:39:13 (GMT)
commite4275f4df36a7cdd58cd4daa7d65b1947a2593d3 (patch)
treeb8dd0fb2998ded4b29a7abdd7ed99797c2558e80 /Lib/dataclasses.py
parent37d8b904f8b5b660f556597b21c0933b841d18de (diff)
downloadcpython-e4275f4df36a7cdd58cd4daa7d65b1947a2593d3.zip
cpython-e4275f4df36a7cdd58cd4daa7d65b1947a2593d3.tar.gz
cpython-e4275f4df36a7cdd58cd4daa7d65b1947a2593d3.tar.bz2
gh-107838: In dataclasses, improve error message when a non-default field follows a default field. (gh-107842)
Add the name of the previous default argument field in an error message.
Diffstat (limited to 'Lib/dataclasses.py')
-rw-r--r--Lib/dataclasses.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/Lib/dataclasses.py b/Lib/dataclasses.py
index 3c72c28..21f3fa5 100644
--- a/Lib/dataclasses.py
+++ b/Lib/dataclasses.py
@@ -575,15 +575,15 @@ def _init_fn(fields, std_fields, kw_only_fields, frozen, has_post_init,
# message, and future-proofs us in case we build up the function
# using ast.
- seen_default = False
+ seen_default = None
for f in std_fields:
# Only consider the non-kw-only fields in the __init__ call.
if f.init:
if not (f.default is MISSING and f.default_factory is MISSING):
- seen_default = True
+ seen_default = f
elif seen_default:
raise TypeError(f'non-default argument {f.name!r} '
- 'follows default argument')
+ f'follows default argument {seen_default.name!r}')
locals = {f'__dataclass_type_{f.name}__': f.type for f in fields}
locals.update({