##// END OF EJS Templates
Use oinspect in CodeMagics._find_edit_target...
Takafumi Arakaki -
Show More
@@ -24,6 +24,7 b' from urllib2 import urlopen'
24 24 from IPython.core.error import TryNext
25 25 from IPython.core.macro import Macro
26 26 from IPython.core.magic import Magics, magics_class, line_magic
27 from IPython.core.oinspect import find_file, find_source_lines
27 28 from IPython.testing.skipdoctest import skip_doctest
28 29 from IPython.utils import openpy
29 30 from IPython.utils import py3compat
@@ -259,8 +260,8 b' class CodeMagics(Magics):'
259 260 raise MacroToEdit(data)
260 261
261 262 # For objects, try to edit the file where they are defined
262 try:
263 filename = inspect.getabsfile(data)
263 filename = find_file(data)
264 if filename:
264 265 if 'fakemodule' in filename.lower() and \
265 266 inspect.isclass(data):
266 267 # class created by %edit? Try to find source
@@ -270,7 +271,7 b' class CodeMagics(Magics):'
270 271 for attr in attrs:
271 272 if not inspect.ismethod(attr):
272 273 continue
273 filename = inspect.getabsfile(attr)
274 filename = find_file(attr)
274 275 if filename and \
275 276 'fakemodule' not in filename.lower():
276 277 # change the attribute to be the edit
@@ -279,7 +280,7 b' class CodeMagics(Magics):'
279 280 break
280 281
281 282 datafile = 1
282 except TypeError:
283 if filename is None:
283 284 filename = make_filename(args)
284 285 datafile = 1
285 286 warn('Could not find file where `%s` is defined.\n'
@@ -287,10 +288,9 b' class CodeMagics(Magics):'
287 288 # Now, make sure we can actually read the source (if it was
288 289 # in a temp file it's gone by now).
289 290 if datafile:
290 try:
291 291 if lineno is None:
292 lineno = inspect.getsourcelines(data)[1]
293 except IOError:
292 lineno = find_source_lines(data)
293 if lineno is None:
294 294 filename = make_filename(args)
295 295 if filename is None:
296 296 warn('The file `%s` where `%s` was defined '
General Comments 0
You need to be logged in to leave comments. Login now