Skip to content

Importing idlelib.run deletes tkinter dialog submodules from sys.modules #156896

Closed

Description

@serhiy-storchaka

Bug report

idlelib/run.py scrubs tkinter at import time (bpo-25507, gh-59396):

for mod in ('simpledialog', 'messagebox', 'font', 'dialog', 'filedialog', 'commondialog', 'ttk'):
    try:
        delattr(tkinter, mod)
        del sys.modules['tkinter.' + mod]
    except (AttributeError, KeyError):
        pass

test_run.py does from idlelib import run, so running it evicts tkinter.commondialog from sys.modules. A later import re-executes commondialog, creating a second Dialog class.

The common-dialog tests cache the class at load (from tkinter.commondialog import Dialog) and patch it with swap_attr(Dialog, '_test_callback', ...). After the re-import that cached class is stale, so the patch misses the class the live dialog uses, and test_colorchooser.test_askcolor opens the real modal color chooser and hangs:

./python -m test -uall test_tkinter test_ttk test_idle

It only fails when test_run runs before the dialog test in the same process (not under -j).

Importing a module shouldn't mutate global sys.modules; idlelib.run should do the scrub only when launched as the subprocess main, not at import.

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    testsTests in the Lib/test dir
    3.13only security fixes
    3.14bugs and security fixes
    3.15bugs and security fixes
    3.16new features, bugs and security fixes
    on Sep 3, 2026
  2. terryjreedy commented on Sep 3, 2026

    @terryjreedy
    Member

    I agree. The purpose is to prevent user code running from IDLE passing when it should fail due to missing tkinter submodule imports. I will add the needed clause to the existing if guard.

  3. terryjreedy commented on Sep 4, 2026

    @terryjreedy
    Member

    Module run is not launched as subprocess main. It is imported with __import__('idlelib.run'), avoiding binding it in main. (Function run.main is run by appending .run.main() to the import.) So I 'guarded' the scrubbing by wrapping it in a function called at the top of main.

  4. added 3 commits that reference this issue on Sep 4, 2026
  5. added a commit that references this issue on Sep 12, 2026
  6. serhiy-storchaka commented on Sep 15, 2026

    @serhiy-storchaka
    MemberAuthor

    Fixed in main by #156915 and backported to 3.13 (#156960) and 3.14 (#156959). The 3.15 backport #156958 is waiting for the release manager.

  7. added a commit that references this issue on Oct 9, 2026
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

    3.13only security fixes3.14bugs and security fixes3.15bugs and security fixes3.16new features, bugs and security fixestestsTests in the Lib/test dirtopic-IDLEtype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions