Skip to content
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

[3.11] gh-106368: Increase Argument Clinic test coverage (#106369) #106374

Merged
Merged
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
57 changes: 57 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,63 @@ def test_other_bizarre_things_in_annotations_fail(self):
)
self.assertEqual(s, expected_failure_message)

def test_self_param_placement(self):
expected_error_msg = (
"Error on line 0:\n"
"A 'self' parameter, if specified, must be the very first thing "
"in the parameter block.\n"
)
block = """
module foo
foo.func
a: int
self: self(type="PyObject *")
"""
out = self.parse_function_should_fail(block)
self.assertEqual(out, expected_error_msg)

def test_self_param_cannot_be_optional(self):
expected_error_msg = (
"Error on line 0:\n"
"A 'self' parameter cannot be marked optional.\n"
)
block = """
module foo
foo.func
self: self(type="PyObject *") = None
"""
out = self.parse_function_should_fail(block)
self.assertEqual(out, expected_error_msg)

def test_defining_class_param_placement(self):
expected_error_msg = (
"Error on line 0:\n"
"A 'defining_class' parameter, if specified, must either be the "
"first thing in the parameter block, or come just after 'self'.\n"
)
block = """
module foo
foo.func
self: self(type="PyObject *")
a: int
cls: defining_class
"""
out = self.parse_function_should_fail(block)
self.assertEqual(out, expected_error_msg)

def test_defining_class_param_cannot_be_optional(self):
expected_error_msg = (
"Error on line 0:\n"
"A 'defining_class' parameter cannot be marked optional.\n"
)
block = """
module foo
foo.func
cls: defining_class(type="PyObject *") = None
"""
out = self.parse_function_should_fail(block)
self.assertEqual(out, expected_error_msg)

def parse(self, text):
c = FakeClinic()
parser = DSLParser(c)
Expand Down