mirror of
https://github.com/python/cpython.git
synced 2026-01-08 00:12:42 +00:00
[3.12] gh-106368: Increase Argument Clinic test coverage (GH-106369) (#106370)
Add tests for 'self' and 'defining_class' converter requirements.
(cherry picked from commit 7f4c8121db)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
This commit is contained in:
parent
887a7e6036
commit
ddff4737bd
1 changed files with 57 additions and 0 deletions
|
|
@ -829,6 +829,63 @@ def test_kwarg_splats_disallowed_in_function_call_annotations(self):
|
|||
out = self.parse_function_should_fail(fn)
|
||||
self.assertEqual(out, expected_error_msg)
|
||||
|
||||
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 test_unused_param(self):
|
||||
block = self.parse("""
|
||||
module foo
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue