mirror of
https://github.com/python/cpython.git
synced 2025-11-08 21:52:45 +00:00
gh-117613: Argument Clinic: disallow defining class parameter at module level (#117950)
This commit is contained in:
parent
a4b44d39cd
commit
c1d7147c82
2 changed files with 11 additions and 0 deletions
|
|
@ -2518,6 +2518,15 @@ class ClinicParserTest(TestCase):
|
||||||
p = function.parameters['cls']
|
p = function.parameters['cls']
|
||||||
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
|
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):
|
class ClinicExternalTest(TestCase):
|
||||||
maxDiff = None
|
maxDiff = None
|
||||||
|
|
|
||||||
|
|
@ -1102,6 +1102,8 @@ class DSLParser:
|
||||||
fail("A 'defining_class' parameter cannot have a default value.")
|
fail("A 'defining_class' parameter cannot have a default value.")
|
||||||
if self.group:
|
if self.group:
|
||||||
fail("A 'defining_class' parameter cannot be in an optional 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
|
kind = inspect.Parameter.POSITIONAL_ONLY
|
||||||
else:
|
else:
|
||||||
fail("A 'defining_class' parameter, if specified, must either "
|
fail("A 'defining_class' parameter, if specified, must either "
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue