Skip to content

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

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

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.13bugs and security fixes3.14bugs and security fixes3.15pre-release feature fixes, bugs 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