Skip to content

Commit

Permalink
pythongh-117613: Argument Clinic: ensure that 'defining_class' params…
Browse files Browse the repository at this point in the history
… are positional-only (python#117781)
  • Loading branch information
neonene authored Apr 16, 2024
1 parent 1316692 commit c520bf9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,16 @@ def test_state_func_docstring_only_one_param_template(self):
"""
self.expect_failure(block, err, lineno=7)

def test_kind_defining_class(self):
function = self.parse_function("""
module m
class m.C "PyObject *" ""
m.C.meth
cls: defining_class
""", signatures_in_block=3, function_index=2)
p = function.parameters['cls']
self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)


class ClinicExternalTest(TestCase):
maxDiff = None
Expand Down
8 changes: 4 additions & 4 deletions Modules/_sqlite/clinic/connection.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Modules/clinic/_testclinic.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Tools/clinic/libclinic/dsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,7 @@ def bad_node(self, node: ast.AST) -> None:
fail("A 'defining_class' parameter cannot have a default value.")
if self.group:
fail("A 'defining_class' parameter cannot be in an optional group.")
kind = inspect.Parameter.POSITIONAL_ONLY
else:
fail("A 'defining_class' parameter, if specified, must either "
"be the first thing in the parameter block, or come just "
Expand Down

0 comments on commit c520bf9

Please sign in to comment.