[Python-checkins] [3.11] gh-106368: Increase Argument Clinic test coverage (#106369) (#106374)
erlend-aasland
webhook-mailer at python.org
Mon Jul 3 18:07:09 EDT 2023
https://github.com/python/cpython/commit/52d5049cfd9f688d40f81194e3ccf7abbe724209
commit: 52d5049cfd9f688d40f81194e3ccf7abbe724209
branch: 3.11
author: Erlend E. Aasland <erlend at python.org>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2023-07-03T22:07:05Z
summary:
[3.11] gh-106368: Increase Argument Clinic test coverage (#106369) (#106374)
Add tests for 'self' and 'defining_class' converter requirements.
(cherry picked from commit 7f4c8121db62a9f72f00f2d9f73381e82f289581)
files:
M Lib/test/test_clinic.py
diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py
index 8d4f92fa310c3..c2d2085ecd6de 100644
--- a/Lib/test/test_clinic.py
+++ b/Lib/test/test_clinic.py
@@ -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)
More information about the Python-checkins
mailing list