Changeset 2917

Show
Ignore:
Timestamp:
12/31/07 08:11:34 (1 year ago)
Author:
vivainio
Message:

allow %edit ClassName? if the class was created by '%edit' (look for the source file from method objs instead of class obj). Closes #132

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • ipython/trunk/IPython/Magic.py

    r2899 r2917  
    22402240                    self._edit_macro(args,data) 
    22412241                    return 
    2242                  
     2242                                 
    22432243                # For objects, try to edit the file where they are defined 
    22442244                try: 
    22452245                    filename = inspect.getabsfile(data) 
     2246                    if 'fakemodule' in filename.lower() and inspect.isclass(data):                      
     2247                        # class created by %edit? Try to find source 
     2248                        # by looking for method definitions instead, the 
     2249                        # __module__ in those classes is FakeModule. 
     2250                        attrs = [getattr(data, aname) for aname in dir(data)] 
     2251                        for attr in attrs: 
     2252                            if not inspect.ismethod(attr): 
     2253                                continue 
     2254                            filename = inspect.getabsfile(attr) 
     2255                            if filename and 'fakemodule' not in filename.lower(): 
     2256                                # change the attribute to be the edit target instead 
     2257                                data = attr  
     2258                                break 
     2259                     
    22462260                    datafile = 1 
    22472261                except TypeError: