Skip to content

Commit 0892d0d

Browse files
committed
Address code review
1 parent fe46de0 commit 0892d0d

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

Lib/test/test_clinic.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ class C "void *" ""
638638
C.__init__ = C.meth
639639
[clinic start generated code]*/
640640
"""
641-
err = "'__init__' must be a normal method, not a classmethod, staticmethod or getter!"
641+
err = "'__init__' must be a normal method; got 'FunctionKind.CLASS_METHOD'!"
642642
self.expect_failure(block, err, lineno=8)
643643

644644
def test_validate_cloned_new(self):
@@ -2180,17 +2180,22 @@ class Foo "" ""
21802180
self.expect_failure(block, err, lineno=2)
21812181

21822182
def test_init_must_be_a_normal_method(self):
2183-
err = "'__init__' must be a normal method, not a classmethod, staticmethod or getter!"
2184-
annotations = ["@classmethod", "@staticmethod", "@getter"]
2185-
for annotation in annotations:
2186-
with self.subTest(annotation=annotation):
2183+
err_template = "'__init__' must be a normal method; got 'FunctionKind.{}'!"
2184+
annotations = {
2185+
"@classmethod": "CLASS_METHOD",
2186+
"@staticmethod": "STATIC_METHOD",
2187+
"@getter": "GETTER",
2188+
}
2189+
for annotation, invalid_kind in annotations.items():
2190+
with self.subTest(annotation=annotation, invalid_kind=invalid_kind):
21872191
block = f"""
21882192
module foo
21892193
class Foo "" ""
21902194
{annotation}
21912195
Foo.__init__
21922196
"""
2193-
self.expect_failure(block, err, lineno=3)
2197+
expected_error = err_template.format(invalid_kind)
2198+
self.expect_failure(block, expected_error, lineno=3)
21942199

21952200
def test_duplicate_coexist(self):
21962201
err = "Called @coexist twice"

Tools/clinic/clinic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,8 +5457,8 @@ def update_function_kind(self, fullname: str) -> None:
54575457
self.kind = METHOD_INIT
54585458
else:
54595459
fail(
5460-
"'__init__' must be a normal method, "
5461-
"not a classmethod, staticmethod or getter!"
5460+
"'__init__' must be a normal method; "
5461+
f"got '{self.kind}'!"
54625462
)
54635463

54645464
def state_modulename_name(self, line: str) -> None:

0 commit comments

Comments
 (0)