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 alexander.belopol...@gmail.com mailto:alexander.belopol...@gmail.com wrote: On Tue, Jul 13, 2010 at 1:57 PM, Benjamin Peterson benja...@python.org mailto:benja...@python.org wrote: .. No! That's

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 st...@holdenweb.com 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

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 ncogh...@gmail.com wrote: On Wed, Jul 14, 2010 at 9:05 PM, Steve Holden st...@holdenweb.com 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

[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

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 alexander.belopol...@gmail.com 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

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 solip...@pitrou.net wrote: On Tue, 13 Jul 2010 11:25:23 -0400 .. Only for top-level modules: __import__(distutils.core, level=0) module 'distutils' from '/home/antoine/py3k/__svn__/Lib/distutils/__init__.py' sys.modules[distutils.core]

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 Pitrousolip...@pitrou.net wrote: On Tue, 13 Jul 2010 11:25:23 -0400 .. Only for top-level modules: __import__(distutils.core, level=0) module 'distutils' from

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

2010-07-13 Thread Benjamin Peterson
2010/7/13 Alexander Belopolsky alexander.belopol...@gmail.com: On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou solip...@pitrou.net wrote: On Tue, 13 Jul 2010 11:25:23 -0400 .. Only for top-level modules: __import__(distutils.core, level=0) module 'distutils' from

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 benja...@python.org wrote: 2010/7/13 Alexander Belopolsky alexander.belopol...@gmail.com: On Tue, Jul 13, 2010 at 11:34 AM, Antoine Pitrou solip...@pitrou.net wrote: On Tue, 13 Jul 2010 11:25:23 -0400 .. Only for top-level modules:

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 benja...@python.org 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) {

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 benja...@python.org wrote: .. No! That's not recommended and a complete hack. The dance or importlib.import_module is preferred. Nevertheless, a

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 br...@python.org 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