Re: [Python-Dev] How to block a module import

2010-07-13 Thread Nick Coghlan
> Nick's right; 0 fails on an import * to pull anything in of interest. And as > I said on python-checkins -- you can ignore that email, Alexander -- there > is a historical reason because in Python 2 if you tried an implicit relative > import a value of None met to do an absolute import. This does

Re: [Python-Dev] How to block a module import

2010-07-13 Thread Alexander Belopolsky
On Tue, Jul 13, 2010 at 4:34 PM, Brett Cannon wrote: .. > Nick's right; 0 fails on an import * to pull anything in of interest. but if the imported module has try: import blocked_module except ImportError: do_something_important() then import_fresh_module() will create a broken module wit

Re: [Python-Dev] How to block a module import

2010-07-13 Thread Brett Cannon
On Tue, Jul 13, 2010 at 05:48, Nick Coghlan wrote: > On Tue, Jul 13, 2010 at 10:37 AM, Alexander Belopolsky > wrote: > > In my experiments, 0 is not equivalent to None: > > > import sys, time > sys.modules['time'] = 0 > __import__('time') > > 0 > sys.modules['time'] = None >

Re: [Python-Dev] How to block a module import

2010-07-13 Thread Nick Coghlan
On Tue, Jul 13, 2010 at 10:37 AM, Alexander Belopolsky wrote: > In my experiments, 0 is not equivalent to None: > import sys, time sys.modules['time'] = 0 __import__('time') > 0 sys.modules['time'] = None __import__('time') > Traceback (most recent call last): >  File "",

[Python-Dev] How to block a module import

2010-07-12 Thread Alexander Belopolsky
I thought that in order to block a module from being imported, one would need to assign None to the corresponding entry in sys.modules. However, it looks like the code in test.support uses 0 instead of None: def _save_and_block_module(name, orig_modules): """Helper function to save and block a