From a8a0e5dc26c83c43d4089fd8e20e1d58a2eca403 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sun, 21 May 2023 23:14:21 +0100 Subject: [PATCH 1/2] Coverage for non-str constants --- Lib/test/test_clinic.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index f72cb0442f35ff..ad2e51d0f0bbb7 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -774,6 +774,24 @@ def test_legacy_converters(self): module, function = block.signatures self.assertIsInstance((function.parameters['path']).converter, clinic.str_converter) + def test_legacy_converters_non_string_constant_annotation(self): + expected_failure_message = """\ +Error on line 0: +Annotations must be either a name, a function call, or a string. +""" + + s = self.parse_function_should_fail('module os\nos.access\n path: 42') + self.assertEqual(s, expected_failure_message) + + s = self.parse_function_should_fail('module os\nos.access\n path: 42.42') + self.assertEqual(s, expected_failure_message) + + s = self.parse_function_should_fail('module os\nos.access\n path: 42j') + self.assertEqual(s, expected_failure_message) + + s = self.parse_function_should_fail('module os\nos.access\n path: b"42"') + self.assertEqual(s, expected_failure_message) + def test_unused_param(self): block = self.parse(""" module foo From 03693464df59c8ce44bf1dc8e0d8ee71deba5d74 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sun, 21 May 2023 23:29:36 +0100 Subject: [PATCH 2/2] Add coverage for the 'everything else should fail' branch --- Lib/test/test_clinic.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Lib/test/test_clinic.py b/Lib/test/test_clinic.py index ad2e51d0f0bbb7..bea7303805567f 100644 --- a/Lib/test/test_clinic.py +++ b/Lib/test/test_clinic.py @@ -792,6 +792,27 @@ def test_legacy_converters_non_string_constant_annotation(self): s = self.parse_function_should_fail('module os\nos.access\n path: b"42"') self.assertEqual(s, expected_failure_message) + def test_other_bizarre_things_in_annotations_fail(self): + expected_failure_message = """\ +Error on line 0: +Annotations must be either a name, a function call, or a string. +""" + + s = self.parse_function_should_fail( + 'module os\nos.access\n path: {"some": "dictionary"}' + ) + self.assertEqual(s, expected_failure_message) + + s = self.parse_function_should_fail( + 'module os\nos.access\n path: ["list", "of", "strings"]' + ) + self.assertEqual(s, expected_failure_message) + + s = self.parse_function_should_fail( + 'module os\nos.access\n path: (x for x in range(42))' + ) + self.assertEqual(s, expected_failure_message) + def test_unused_param(self): block = self.parse(""" module foo