From b8e40c9c8244874073bd3614dda60dc99165265c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Wed, 2 Dec 2026 15:24:42 +0100 Subject: [PATCH] gh-108271: Name the class in Argument Clinic alias errors for __new__ The `TypeError` raised when both a parameter and its alias are given named `__new__()` instead of the class for constructors declared as `__new__`, unlike the other errors raised by the generated parsers. --- Lib/test/test_clinic.py | 15 +++++++++++++++ Tools/clinic/libclinic/parse_args.py | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index cb4ed55fabbbc1..acf99b172f37b6 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -688,6 +688,21 @@ class C "void *" "" err = "'__new__' must be a class method" self.expect_failure(block, err, lineno=7) + def test_alias_new_error_message(self): + block = dedent(""" + /*[clinic input] + output everything block + class C "void *" "" + @classmethod + C.__new__ + a: object = None + * + b as a: object = None + [clinic start generated code]*/ + """) + generated = self.clinic.parse(block) + self.assertIn('"argument for C() given by "', generated) + def test_no_c_basename_cloned(self): block = """ /*[clinic input] diff --git a/Tools/clinic/libclinic/parse_args.py b/Tools/clinic/libclinic/parse_args.py index ab8d1add84daa4..69aef7d8fee7f1 100644 --- a/Tools/clinic/libclinic/parse_args.py +++ b/Tools/clinic/libclinic/parse_args.py @@ -1171,7 +1171,7 @@ def render_alias(self, p: Parameter, argname_fmt: str, libclinic.normalize_snippet(f""" if ({argname_fmt % i}) {{{{ PyErr_Format(PyExc_TypeError, - "argument for {self.func.name}() given by " + "argument for {self.func.displayname}() given by " "name ('{p.name}') and {other}"{arg}); goto exit; }}}}