Skip to content

gh-117613: Argument Clinic: disallow defining_class parameter at module level #117950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2518,6 +2518,15 @@ class m.C "PyObject *" ""
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
Expand Down
2 changes: 2 additions & 0 deletions Tools/clinic/libclinic/dsl_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,8 @@ 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.")
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 "
Expand Down