Skip to content

Argument Clinic duplicate module check is malfunctioning #107609

Closed

Description

@erlend-aasland

The following code is silently accepted by Argument Clinic:

/*[clinic input]
module m
module m
[clinic start generated code]*/

The duplicate module m should have been caught by Argument Clinic, but the guard is faulty:

cpython/Tools/clinic/clinic.py

Lines 4481 to 4482 in 9e6590b

if name in module.classes:
fail("Already defined module " + repr(name) + "!")

The check should be against .modules, not .classes:

diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py
index 1bcdb6b1c3..dc4a7f9318 100755
--- a/Tools/clinic/clinic.py
+++ b/Tools/clinic/clinic.py
@@ -4478,7 +4478,7 @@ def directive_module(self, name: str) -> None:
         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)

See also the Module class:

cpython/Tools/clinic/clinic.py

Lines 2384 to 2392 in 9e6590b

class Module:
name: str
module: Module | Clinic
def __post_init__(self) -> None:
self.parent = self.module
self.modules: ModuleDict = {}
self.classes: ClassDict = {}
self.functions: list[Function] = []

Linked PRs

Activity

  1. added
    type-bug
    on Aug 3, 2023
  2. erlend-aasland commented on Aug 3, 2023

    @erlend-aasland
    ContributorAuthor

    Discovered while expanding the test suite to cover all directives and commands.

  3. added 2 commits that reference this issue on Aug 3, 2023
  4. added a commit that references this issue on Aug 4, 2023
  5. erlend-aasland commented on Aug 4, 2023

    @erlend-aasland
    ContributorAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-argument-clinictype-bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions