]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106368: Argument clinic: Fix minor bug in `state_modulename_name` (#107387)
authorAlex Waygood <Alex.Waygood@Gmail.com>
Fri, 28 Jul 2023 18:10:45 +0000 (19:10 +0100)
committerGitHub <noreply@github.com>
Fri, 28 Jul 2023 18:10:45 +0000 (19:10 +0100)
Lib/test/test_clinic.py
Tools/clinic/clinic.py

index 2f74ee29b204dbf41f5e4dc2e539198e699a1457..3ce27d1dd6b487040ee065b5a662cea4f4334344 100644 (file)
@@ -84,6 +84,7 @@ class FakeClinic:
             ('parser_definition', d('block')),
             ('impl_definition', d('block')),
         ))
+        self.functions = []
 
     def get_destination(self, name):
         d = self.destinations.get(name)
@@ -104,6 +105,9 @@ class FakeClinic:
 
     _module_and_class = clinic.Clinic._module_and_class
 
+    def __repr__(self):
+        return "<FakeClinic object>"
+
 
 class ClinicWholeFileTest(_ParserBase):
     def setUp(self):
@@ -672,6 +676,19 @@ class ClinicParserTest(_ParserBase):
         """)
         self.assertEqual("os_stat_fn", function.c_basename)
 
+    def test_cloning_nonexistent_function_correctly_fails(self):
+        stdout = self.parse_function_should_fail("""
+            cloned = fooooooooooooooooooooooo
+            This is trying to clone a nonexistent function!!
+        """)
+        expected_error = """\
+cls=None, module=<FakeClinic object>, existing='fooooooooooooooooooooooo'
+(cls or module).functions=[]
+Error on line 0:
+Couldn't find existing function 'fooooooooooooooooooooooo'!
+"""
+        self.assertEqual(expected_error, stdout)
+
     def test_return_converter(self):
         function = self.parse_function("""
             module os
index a343dc5c7fc080884c0cdafe742cb4545adc34f0..39c6de35273019b97fad1661acb876531e0e2f27 100755 (executable)
@@ -4707,11 +4707,9 @@ class DSLParser:
                     if existing_function.name == function_name:
                         break
                 else:
-                    existing_function = None
-                if not existing_function:
-                    print("class", cls, "module", module, "existing", existing)
-                    print("cls. functions", cls.functions)
-                    fail("Couldn't find existing function " + repr(existing) + "!")
+                    print(f"{cls=}, {module=}, {existing=}")
+                    print(f"{(cls or module).functions=}")
+                    fail(f"Couldn't find existing function {existing!r}!")
 
                 fields = [x.strip() for x in full_name.split('.')]
                 function_name = fields.pop()