Re: avoid import short-circuiting

2012-03-16 Thread Robert Kern
On 3/16/12 11:14 PM, Andrea Crotti wrote: Very nice thanks, here it is class ImportMock: def _my_import(self, *args, **kwargs): self.ls.append(args[0]) self.orig(*args, **kwargs) There's a bug here. You need to return the module object you got from calling self.orig(). By

Re: avoid import short-circuiting

2012-03-16 Thread Andrea Crotti
On 03/16/2012 10:20 PM, Robert Kern wrote: On 3/16/12 10:04 PM, Andrea Crotti wrote: On 03/16/2012 05:19 PM, Robert Kern wrote: On 3/16/12 4:49 PM, Andrea Crotti wrote: I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what ex

Re: avoid import short-circuiting

2012-03-16 Thread Robert Kern
On 3/16/12 10:04 PM, Andrea Crotti wrote: On 03/16/2012 05:19 PM, Robert Kern wrote: On 3/16/12 4:49 PM, Andrea Crotti wrote: I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what exactly depends on what at run-time, using an

Re: avoid import short-circuiting

2012-03-16 Thread Ian Kelly
On Fri, Mar 16, 2012 at 4:04 PM, Andrea Crotti wrote: >> You want to monkeypatch __builtin__.__import__() instead. It always gets >> called. >> > > Seems like a good idea :) > > My first attempt failes though > > > def full(module): >    from __builtin__ import __import__ >    ls = [] >    orig =

Re: avoid import short-circuiting

2012-03-16 Thread Andrea Crotti
On 03/16/2012 05:19 PM, Robert Kern wrote: On 3/16/12 4:49 PM, Andrea Crotti wrote: I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what exactly depends on what at run-time, using an import hook. It works quite well for sma

Re: avoid import short-circuiting

2012-03-16 Thread Robert Kern
On 3/16/12 4:49 PM, Andrea Crotti wrote: I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what exactly depends on what at run-time, using an import hook. It works quite well for small examples but the main problem is that once

Re: avoid import short-circuiting

2012-03-16 Thread Ethan Furman
Andrea Crotti wrote: I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what exactly depends on what at run-time, using an import hook. It works quite well for small examples but the main problem is that once a module is impor

avoid import short-circuiting

2012-03-16 Thread Andrea Crotti
I started the following small project: https://github.com/AndreaCrotti/import-tree because I would like to find out what exactly depends on what at run-time, using an import hook. It works quite well for small examples but the main problem is that once a module is imported it's added to sys.