Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-14 Thread Brett Cannon
On Wed, Jul 14, 2010 at 05:15, Nick Coghlan wrote: > On Wed, Jul 14, 2010 at 9:05 PM, Steve Holden wrote: > >> I have stopped fixing bugs related to this in import.c because of the > >> annoying issues it causes and I expect the correct approach to gain > >> traction at some point (plus get impo

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-14 Thread Nick Coghlan
On Wed, Jul 14, 2010 at 9:05 PM, Steve Holden wrote: >> I have stopped fixing bugs related to this in import.c because of the >> annoying issues it causes and I expect the correct approach to gain >> traction at some point (plus get importlib bootstrapped in so I don't >> have to care about import

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-14 Thread Steve Holden
Brett Cannon wrote: > > > On Tue, Jul 13, 2010 at 11:34, Alexander Belopolsky > mailto:alexander.belopol...@gmail.com>> > wrote: > > On Tue, Jul 13, 2010 at 1:57 PM, Benjamin Peterson > mailto:benja...@python.org>> wrote: > .. > > No! That's not recommended and a complete hack. T

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Alexander Belopolsky
On Tue, Jul 13, 2010 at 4:52 PM, Brett Cannon wrote: .. > Pulling from sys.modules is the correct way to do this. There are subtle > issues when using a bunk fromlist argument (empty modules, double > initialization, etc.). If one does not use importlib.import_module -- > written *specifically* to

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Brett Cannon
On Tue, Jul 13, 2010 at 11:34, Alexander Belopolsky < alexander.belopol...@gmail.com> wrote: > On Tue, Jul 13, 2010 at 1:57 PM, Benjamin Peterson > wrote: > .. > > No! That's not recommended and a complete hack. The "dance" or > > importlib.import_module is preferred. > > Nevertheless, "a complet

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Alexander Belopolsky
On Tue, Jul 13, 2010 at 1:57 PM, Benjamin Peterson wrote: .. > No! That's not recommended and a complete hack. The "dance" or > importlib.import_module is preferred. Nevertheless, "a complete hack" is what PyImport_Import does: PyObject * PyImport_Import(PyObject *module_name) { static PyObj

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Jack Diederich
On Tue, Jul 13, 2010 at 1:57 PM, Benjamin Peterson wrote: > 2010/7/13 Alexander Belopolsky : >> On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou wrote: >>> On Tue, 13 Jul 2010 11:25:23 -0400 >> .. >>> Only for top-level modules: >>> >> __import__("distutils.core", level=0) >>> >> '/home/antoi

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Benjamin Peterson
2010/7/13 Alexander Belopolsky : > On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou wrote: >> On Tue, 13 Jul 2010 11:25:23 -0400 > .. >> Only for top-level modules: >> > __import__("distutils.core", level=0) >> > '/home/antoine/py3k/__svn__/Lib/distutils/__init__.py'> > sys.modules["distut

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Michael Foord
On 13/07/2010 16:46, Alexander Belopolsky wrote: On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou wrote: On Tue, 13 Jul 2010 11:25:23 -0400 .. Only for top-level modules: __import__("distutils.core", level=0) sys.modules["distutils.core"]

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Alexander Belopolsky
On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou wrote: > On Tue, 13 Jul 2010 11:25:23 -0400 .. > Only for top-level modules: > __import__("distutils.core", level=0) > '/home/antoine/py3k/__svn__/Lib/distutils/__init__.py'> sys.modules["distutils.core"] > '/home/antoine/py3k/__svn__/Li

Re: [Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Antoine Pitrou
On Tue, 13 Jul 2010 11:25:23 -0400 Alexander Belopolsky wrote: > When pickle.py needs to import a module by name, it goes through a > peculiar dance of > > __import__(module, level=0) > mod = sys.modules[module] > > As far as I can tell, unless builtins.__import__ is over

[Python-Dev] Peculiar import code in pickle.py

2010-07-13 Thread Alexander Belopolsky
When pickle.py needs to import a module by name, it goes through a peculiar dance of __import__(module, level=0) mod = sys.modules[module] As far as I can tell, unless builtins.__import__ is overridden or sys.modules clobbered by user code, the above should be equivalent t