Skip to content

Commit c520bf9

Browse files
authored
pythongh-117613: Argument Clinic: ensure that 'defining_class' params are positional-only (python#117781)
1 parent 1316692 commit c520bf9

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

Lib/test/test_clinic.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,16 @@ def test_state_func_docstring_only_one_param_template(self):
25082508
"""
25092509
self.expect_failure(block, err, lineno=7)
25102510

2511+
def test_kind_defining_class(self):
2512+
function = self.parse_function("""
2513+
module m
2514+
class m.C "PyObject *" ""
2515+
m.C.meth
2516+
cls: defining_class
2517+
""", signatures_in_block=3, function_index=2)
2518+
p = function.parameters['cls']
2519+
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
2520+
25112521

25122522
class ClinicExternalTest(TestCase):
25132523
maxDiff = None

Modules/_sqlite/clinic/connection.c.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/clinic/_testclinic.c.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Tools/clinic/libclinic/dsl_parser.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,7 @@ def bad_node(self, node: ast.AST) -> None:
11021102
fail("A 'defining_class' parameter cannot have a default value.")
11031103
if self.group:
11041104
fail("A 'defining_class' parameter cannot be in an optional group.")
1105+
kind = inspect.Parameter.POSITIONAL_ONLY
11051106
else:
11061107
fail("A 'defining_class' parameter, if specified, must either "
11071108
"be the first thing in the parameter block, or come just "

0 commit comments

Comments
 (0)