diff options
author | neonene <53406459+neonene@users.noreply.github.com> | 2024-04-17 20:43:29 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 20:43:29 (GMT) |
commit | c1d7147c820545bb0a97a072fdba82154fd97ab6 (patch) | |
tree | 2e73a51fc04ee0a6add03c305d83df80293d547a | |
parent | a4b44d39cd6941cc03590fee7538776728bdfd0a (diff) | |
download | cpython-c1d7147c820545bb0a97a072fdba82154fd97ab6.zip cpython-c1d7147c820545bb0a97a072fdba82154fd97ab6.tar.gz cpython-c1d7147c820545bb0a97a072fdba82154fd97ab6.tar.bz2 |
gh-117613: Argument Clinic: disallow defining class parameter at module level (#117950)
-rw-r--r-- | Lib/test/test_clinic.py | 9 | ||||
-rw-r--r-- | Tools/clinic/libclinic/dsl_parser.py | 2 |
2 files changed, 11 insertions, 0 deletions
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index 43b629f..d9e4ce2 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -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 diff --git a/Tools/clinic/libclinic/dsl_parser.py b/Tools/clinic/libclinic/dsl_parser.py index 56c6dca..cb18374 100644 --- a/Tools/clinic/libclinic/dsl_parser.py +++ b/Tools/clinic/libclinic/dsl_parser.py @@ -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 " |