This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients Decorater, brett.cannon, eric.snow, gvanrossum, ncoghlan, r.david.murray, terry.reedy
Date 2016-07-15.08:39:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1468571943.86.0.44801926567.issue27515@psf.upfronthosting.co.za>
In-reply-to
Content
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)
History
Date User Action Args
2016-07-15 08:39:03ncoghlansetrecipients: + ncoghlan, gvanrossum, brett.cannon, terry.reedy, r.david.murray, eric.snow, Decorater
2016-07-15 08:39:03ncoghlansetmessageid: <1468571943.86.0.44801926567.issue27515@psf.upfronthosting.co.za>
2016-07-15 08:39:03ncoghlanlinkissue27515 messages
2016-07-15 08:39:03ncoghlancreate