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