Nick Coghlan added the comment:

To fully remove an imported submodule, you also need to purge it from the 
sys.modules cache:

    >>> import email.charset; email.charset
    <module 'email.charset' from '/usr/lib64/python3.5/email/charset.py'>
    >>> import sys
    >>> del email.charset; del sys.modules["email.charset"]
    >>> import email.charset; email.charset
    <module 'email.charset' from '/usr/lib64/python3.5/email/charset.py'>

The reason we don't provide utilities in importlib to purge modules that way is 
because not all modules support being forcibly reloaded like this, and unlike 
imp.reload(), the errors happen at the point of importing it again later, not 
at the point where you purge it.

However, if you can figure out precisely which "tk" submodules IDLE implicitly 
imports, you can do one of three things for each one:

1. Change IDLE to avoid importing it in the subprocess where user code runs;
2. Test it supports reloading, and do "del tk.<submodule>; del 
sys.modules['tk.<submodule>']" in the IDLE subprocess after you're finished 
with it; or
3. Change tk.__init__ to implicitly import that submodule (such that code that 
only imports "tk" will still be able to access it)

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27515>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to