mirror of https://github.com/python/cpython
gh-117613: Argument Clinic: disallow defining class parameter at module level (#117950)
This commit is contained in:
parent
a4b44d39cd
commit
c1d7147c82
|
@ -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
|
||||
|
|
|
@ -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 "
|
||||
|
|
Loading…
Reference in New Issue