Skip to content

Commit 15770bf

Browse files
erlend-aaslandmiss-islington
authored andcommitted
pythongh-107609: Fix duplicate module check in Argument Clinic (pythonGH-107610)
Also remove duplicate module def from _testcapi. (cherry picked from commit a443c31) Co-authored-by: Erlend E. Aasland <erlend@python.org>
1 parent 58af229 commit 15770bf

4 files changed

Lines changed: 15 additions & 3 deletions

File tree

‎Lib/test/test_clinic.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,16 @@ def converter_init(self):
334334
)
335335
self.assertIn(msg, out)
336336

337+
def test_module_already_got_one(self):
338+
err = "Already defined module 'm'!"
339+
block = """
340+
/*[clinic input]
341+
module m
342+
module m
343+
[clinic start generated code]*/
344+
"""
345+
self.expect_failure(block, err, lineno=3)
346+
337347

338348
class ClinicGroupPermuterTest(TestCase):
339349
def _test(self, l, m, r, output):
Lines changed: 3 additions & 0 deletions
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‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,9 @@ VectorCallClass_vectorcall(PyObject *callable,
157157
}
158158

159159
/*[clinic input]
160-
module _testcapi
161160
class _testcapi.VectorCallClass "PyObject *" "&PyType_Type"
162161
[clinic start generated code]*/
163-
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=8423a8e919f2f0df]*/
162+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=95c63c1a47f9a995]*/
164163

165164
/*[clinic input]
166165
_testcapi.VectorCallClass.set_vectorcall

‎Tools/clinic/clinic.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4324,7 +4324,7 @@ def directive_module(self, name: str) -> None:
43244324
if cls:
43254325
fail("Can't nest a module inside a class!")
43264326

4327-
if name in module.classes:
4327+
if name in module.modules:
43284328
fail("Already defined module " + repr(name) + "!")
43294329

43304330
m = Module(name, module)

0 commit comments

Comments
 (0)