##// END OF EJS Templates
Fix bug reported by Jeremy Jones where %pfile would fail on object...
Fernando Perez -
Show More
@@ -155,7 +155,12 b' def getsource(obj,is_binary=False):'
155 155 if is_binary:
156 156 return None
157 157 else:
158 return inspect.getsource(obj)
158 try:
159 src = inspect.getsource(obj)
160 except TypeError:
161 if hasattr(obj,'__class__'):
162 src = inspect.getsource(obj.__class__)
163 return src
159 164
160 165 #****************************************************************************
161 166 # Class definitions
@@ -293,11 +298,22 b' class Inspector:'
293 298
294 299 def pfile(self,obj,oname=''):
295 300 """Show the whole file where an object was defined."""
301
302 try:
296 303 try:
297 sourcelines,lineno = inspect.getsourcelines(obj)
304 lineno = inspect.getsourcelines(obj)[1]
305 except TypeError:
306 # For instances, try the class object like getsource() does
307 if hasattr(obj,'__class__'):
308 lineno = inspect.getsourcelines(obj.__class__)[1]
309 # Adjust the inspected object so getabsfile() below works
310 obj = obj.__class__
298 311 except:
299 312 self.noinfo('file',oname)
300 else:
313 return
314
315 # We only reach this point if object was successfully queried
316
301 317 # run contents of file through pager starting at line
302 318 # where the object is defined
303 319 ofile = inspect.getabsfile(obj)
@@ -307,9 +323,10 b' class Inspector:'
307 323 elif not os.path.isfile(ofile):
308 324 print 'File %r does not exist, not printing.' % ofile
309 325 else:
310 # Print only text files, not extension binaries.
311 page(self.format(open(ofile).read()),lineno)
312 #page(self.format(open(inspect.getabsfile(obj)).read()),lineno)
326 # Print only text files, not extension binaries. Note that
327 # getsourcelines returns lineno with 1-offset and page() uses
328 # 0-offset, so we must adjust.
329 page(self.format(open(ofile).read()),lineno-1)
313 330
314 331 def pinfo(self,obj,oname='',formatter=None,info=None,detail_level=0):
315 332 """Show detailed information about an object.
@@ -1529,6 +1529,9 b' def page(strng,start=0,screen_lines=0,pager_cmd = None):'
1529 1529 written in python, very simplistic.
1530 1530 """
1531 1531
1532 # Some routines may auto-compute start offsets incorrectly and pass a
1533 # negative value. Offset to 0 for robustness.
1534 start = max(0,start)
1532 1535
1533 1536 # first, try the hook
1534 1537 ip = IPython.ipapi.get()
General Comments 0
You need to be logged in to leave comments. Login now