Skip to content

Commit b8e40c9

Browse files
committed
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.
1 parent c8d892e commit b8e40c9

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎Lib/test/test_clinic.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,21 @@ class C "void *" ""
688688
err = "'__new__' must be a class method"
689689
self.expect_failure(block, err, lineno=7)
690690

691+
def test_alias_new_error_message(self):
692+
block = dedent("""
693+
/*[clinic input]
694+
output everything block
695+
class C "void *" ""
696+
@classmethod
697+
C.__new__
698+
a: object = None
699+
*
700+
b as a: object = None
701+
[clinic start generated code]*/
702+
""")
703+
generated = self.clinic.parse(block)
704+
self.assertIn('"argument for C() given by "', generated)
705+
691706
def test_no_c_basename_cloned(self):
692707
block = """
693708
/*[clinic input]

‎Tools/clinic/libclinic/parse_args.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ def render_alias(self, p: Parameter, argname_fmt: str,
11711171
libclinic.normalize_snippet(f"""
11721172
if ({argname_fmt % i}) {{{{
11731173
PyErr_Format(PyExc_TypeError,
1174-
"argument for {self.func.name}() given by "
1174+
"argument for {self.func.displayname}() given by "
11751175
"name ('{p.name}') and {other}"{arg});
11761176
goto exit;
11771177
}}}}

0 commit comments

Comments
 (0)