[IPython-dev] potential extension to ?? magic, etc

Michael McKerns mmckerns at caltech.edu
Fri May 9 16:55:53 EDT 2014


I've been hacking a new feature in dill that extracts importable
source code from python objects.  It's still kind of fragile, and
some things don't work like I want, but it's starting to come
around enough that I thought I'd share.

I think it might be useful for ipython's "??" and also for python.parallel
if it still sends source in certain cases.  I know parallelpython (pp) does,
and it augments the heck out of what pp can send across the wire.

There's several useful functions in dill.source and dill.detect, but the
main one is dill.source.importable.

With it, you can do something like this:

>>> def foo(f):
...   def squared(x):
...     return f(x)**2
...   return squared
...
>>> @foo
... def bar(x):
...   return 2*x
...
>>> print dill.source.importable(bar)
def foo(f):
  def squared(x):
    return f(x)**2
  return squared

@foo
def bar(x):
  return 2*x



There are still some bugs, as this is fairly new.  :)

---

Mike McKerns
California Institute of Technology
TEL: (626)395-5773 or (626)590-8470
http://www.its.caltech.edu/~mmckerns
mmckerns at caltech.edu




More information about the IPython-dev mailing list