8000 gh-115077: Make some Argument Clinic error messages more helpful by erlend-aasland · Pull Request #115078 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-115077: Make some Argument Clinic error messages more helpful #115078

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

Closed
6 changes: 3 additions & 3 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class C "void *" ""
C.__init__ = C.meth
[clinic start generated code]*/
"""
err = "'__init__' must be a normal method; got 'FunctionKind.CLASS_METHOD'!"
err = "'__init__' must be an instance method; got 'FunctionKind.CLASS_METHOD'"
self.expect_failure(block, err, lineno=8)

def test_validate_cloned_new(self):
Expand Down Expand Up @@ -2132,7 +2132,7 @@ class Foo "" ""
self.parse_function(block)

def test_new_must_be_a_class_method(self):
err = "'__new__' must be a class method!"
err = "'__new__' must be a class method; got 'FunctionKind.CALLABLE'"
block = """
module foo
class Foo "" ""
Expand All @@ -2141,7 +2141,7 @@ class Foo "" ""
self.expect_failure(block, err, lineno=2)

def test_init_must_be_a_normal_method(self):
err_template = "'__init__' must be a normal method; got 'FunctionKind.{}'!"
err_template = "'__init__' must be an instance method; got 'FunctionKind.{}'"
annotations = {
"@classmethod": "CLASS_METHOD",
"@staticmethod": "STATIC_METHOD",
Expand Down
4 changes: 2 additions & 2 deletions Tools/clinic/clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -5093,9 +5093,9 @@ def normalize_function_kind(self, fullname: str) -> None:
if name in unsupported_special_methods:
fail(f"{name!r} is a special method and cannot be converted to Argument Clinic!")
if name == '__init__' and (self.kind is not CALLABLE or not cls):
fail(f"{name!r} must be a normal method; got '{self.kind}'!")
fail(f"{name!r} must be an instance method; got '{self.kind}'!")
if name == '__new__' and (self.kind is not CLASS_METHOD or not cls):
fail("'__new__' must be a class method!")
fail(f"'__new__' must be a class method; got '{self.kind}'")
if self.kind in {GETTER, SETTER} and not cls:
fail("@getter and @setter must be methods")

Expand Down
0