gh-117613: Argument Clinic: disallow defining class parameter at module level (#117950)

This commit is contained in:
neonene 2024-04-18 05:43:29 +09:00 committed by GitHub
parent a4b44d39cd
commit c1d7147c82
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -2518,6 +2518,15 @@ class ClinicParserTest(TestCase):
p = function.parameters['cls']
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
def test_disallow_defining_class_at_module_level(self):
err = "A 'defining_class' parameter cannot be defined at module level."
block = """
module m
m.func
cls: defining_class
"""
self.expect_failure(block, err, lineno=2)
class ClinicExternalTest(TestCase):
maxDiff = None

View File

@ -1102,6 +1102,8 @@ class DSLParser:
fail("A 'defining_class' parameter cannot have a default value.")
if self.group:
fail("A 'defining_class' parameter cannot be in an optional group.")
if self.function.cls is None:
fail("A 'defining_class' parameter cannot be defined at module level.")
kind = inspect.Parameter.POSITIONAL_ONLY
else:
fail("A 'defining_class' parameter, if specified, must either "