]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-107609: Fix duplicate module check in Argument Clinic (#107610)
authorErlend E. Aasland <erlend@python.org>
Fri, 4 Aug 2023 05:28:25 +0000 (07:28 +0200)
committerGitHub <noreply@github.com>
Fri, 4 Aug 2023 05:28:25 +0000 (07:28 +0200)
Also remove duplicate module def from _testcapi.

Lib/test/test_clinic.py
Misc/NEWS.d/next/Tools-Demos/2023-08-04-00-04-40.gh-issue-107609.2DqgtL.rst [new file with mode: 0644]
Modules/_testcapi/vectorcall.c
Tools/clinic/clinic.py

index 3aa41631d3637a8c3d97170ab4e2dc49d3dff088..59669d61f01bd8d1a2dad15fb6d4b65ef3eb2774 100644 (file)
@@ -416,6 +416,16 @@ class ClinicWholeFileTest(TestCase):
         """
         self.expect_failure(block, err, lineno=8)
 
+    def test_module_already_got_one(self):
+        err = "Already defined module 'm'!"
+        block = """
+            /*[clinic input]
+            module m
+            module m
+            [clinic start generated code]*/
+        """
+        self.expect_failure(block, err, lineno=3)
+
 
 class ClinicGroupPermuterTest(TestCase):
     def _test(self, l, m, r, output):
diff --git a/Misc/NEWS.d/next/Tools-Demos/2023-08-04-00-04-40.gh-issue-107609.2DqgtL.rst b/Misc/NEWS.d/next/Tools-Demos/2023-08-04-00-04-40.gh-issue-107609.2DqgtL.rst
new file mode 100644 (file)
index 0000000..080a6c1
--- /dev/null
@@ -0,0 +1,3 @@
+Fix duplicate module check in Argument Clinic. Previously, a duplicate
+definition would incorrectly be silently accepted. Patch by Erlend E.
+Aasland.
index 61c6e0f485f47eee956076bf528139de176600cb..2b5110fcba2c91faa64e7737a9f3b197395afaa0 100644 (file)
@@ -155,10 +155,9 @@ VectorCallClass_vectorcall(PyObject *callable,
 }
 
 /*[clinic input]
-module _testcapi
 class _testcapi.VectorCallClass "PyObject *" "&PyType_Type"
 [clinic start generated code]*/
-/*[clinic end generated code: output=da39a3ee5e6b4b0d input=8423a8e919f2f0df]*/
+/*[clinic end generated code: output=da39a3ee5e6b4b0d input=95c63c1a47f9a995]*/
 
 /*[clinic input]
 _testcapi.VectorCallClass.set_vectorcall
index 733a83ee58c0f48a87a1f2c7b6197492790c0da1..7525c1ca5240034a96a5c75915b7998e04e1b8c8 100755 (executable)
@@ -4472,7 +4472,7 @@ class DSLParser:
         if cls:
             fail("Can't nest a module inside a class!")
 
-        if name in module.classes:
+        if name in module.modules:
             fail("Already defined module " + repr(name) + "!")
 
         m = Module(name, module)