MCPcopy Create free account
hub / github.com/ipython/ipython / pfile

Method pfile

IPython/core/oinspect.py:492–512  ·  view source on GitHub ↗

Show the whole file where an object was defined.

(self, obj, oname='')

Source from the content-addressed store, hash-verified

490 page.page(self.format(src))
491
492 def pfile(self, obj, oname=''):
493 """Show the whole file where an object was defined."""
494
495 lineno = find_source_lines(obj)
496 if lineno is None:
497 self.noinfo('file', oname)
498 return
499
500 ofile = find_file(obj)
501 # run contents of file through pager starting at line where the object
502 # is defined, as long as the file isn't binary and is actually on the
503 # filesystem.
504 if ofile.endswith(('.so', '.dll', '.pyd')):
505 print('File %r is binary, not printing.' % ofile)
506 elif not os.path.isfile(ofile):
507 print('File %r does not exist, not printing.' % ofile)
508 else:
509 # Print only text files, not extension binaries. Note that
510 # getsourcelines returns lineno with 1-offset and page() uses
511 # 0-offset, so we must adjust.
512 page.page(self.format(openpy.read_py_file(ofile, skip_encoding_cookie=False)), lineno - 1)
513
514
515 def _mime_format(self, text:str, formatter=None) -> dict:

Callers

nothing calls this directly

Calls 5

noinfoMethod · 0.95
find_source_linesFunction · 0.85
find_fileFunction · 0.85
pageMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected