Skip to content

Commit a443c31

Browse files
gh-107609: Fix duplicate module check in Argument Clinic (#107610)
Also remove duplicate module def from _testcapi.
1 parent e52e87c commit a443c31

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

Lib/test/test_clinic.py

+10
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,16 @@ def __init__(self):
416416
"""
417417
self.expect_failure(block, err, lineno=8)
418418

419+
def test_module_already_got_one(self):
420+
err = "Already defined module 'm'!"
421+
block = """
422+
/*[clinic input]
423+
module m
424+
module m
425+
[clinic start generated code]*/
426+
"""
427+
self.expect_failure(block, err, lineno=3)
428+
419429

420430
class ClinicGroupPermuterTest(TestCase):
421431
def _test(self, l, m, r, output):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix duplicate module check in Argument Clinic. Previously, a duplicate
2+
definition would incorrectly be silently accepted. Patch by Erlend E.
3+
Aasland.

Modules/_testcapi/vectorcall.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,9 @@ VectorCallClass_vectorcall(PyObject *callable,
155155
}
156156

157157
/*[clinic input]
158-
module _testcapi
159158
class _testcapi.VectorCallClass "PyObject *" "&PyType_Type"
160159
[clinic start generated code]*/
161-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=8423a8e919f2f0df]*/
160+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=95c63c1a47f9a995]*/
162161

163162
/*[clinic input]
164163
_testcapi.VectorCallClass.set_vectorcall

Tools/clinic/clinic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4472,7 +4472,7 @@ def directive_module(self, name: str) -> None:
44724472
if cls:
44734473
fail("Can't nest a module inside a class!")
44744474

4475-
if name in module.classes:
4475+
if name in module.modules:
44764476
fail("Already defined module " + repr(name) + "!")
44774477

44784478
m = Module(name, module)

0 commit comments

Comments
 (0)