Object Inspectors (xonsh.inspectors
)¶
Tools for inspecting Python objects.
This file was forked from the IPython project:
- Copyright (c) 2008-2014, IPython Development Team
- Copyright (C) 2001-2007 Fernando Perez <fperez@colorado.edu>
- Copyright (c) 2001, Janko Hauser <jhauser@zscout.de>
- Copyright (c) 2001, Nathaniel Gray <n8gray@caltech.edu>
-
class
xonsh.inspectors.
Inspector
(str_detail_level=0)[source]¶ Inspects objects.
-
info
(obj, oname='', info=None, detail_level=0)[source]¶ Compute a dict with detailed information about an object.
Optional arguments:
- oname: name of the variable pointing to the object.
- info: a structure with some information fields which may have been precomputed already.
- detail_level: if set to 1, more information is given.
-
pdef
(obj, oname='')[source]¶ Print the call signature for any callable object.
If the object is a class, print the constructor information.
-
pdoc
(obj, oname='')[source]¶ Print the docstring for any object.
Optional
-formatter: a function to run the docstring through for specially formatted docstrings.
-
pinfo
(obj, oname='', info=None, detail_level=0)[source]¶ Show detailed information about an object.
Parameters: obj : object
oname : str, optional
name of the variable pointing to the object.
info : dict, optional
a structure with some information fields which may have been precomputed already.
detail_level : int, optional
if set to 1, more information is given.
-
pinfo_fields1
= [('Type', 'type_name')]¶
-
pinfo_fields2
= [('String form', 'string_form')]¶
-
pinfo_fields3
= [('Length', 'length'), ('File', 'file'), ('Definition', 'definition')]¶
-
pinfo_fields_obj
= [('Class docstring', 'class_docstring'), ('Init docstring', 'init_docstring'), ('Call def', 'call_def'), ('Call docstring', 'call_docstring')]¶
-
-
xonsh.inspectors.
call_tip
(oinfo, format_call=True)[source]¶ Extract call tip data from an oinfo dict.
Parameters: oinfo : dict
format_call : bool, optional
If True, the call line is formatted and returned as a string. If not, a tuple of (name, argspec) is returned.
Returns: call_info : None, str or (str, dict) tuple.
When format_call is True, the whole call information is formatted as a single string. Otherwise, the object’s name and its argspec dict are returned. If no call information is available, None is returned.
docstring : str or None
The most relevant docstring for calling purposes is returned, if available. The priority is: call docstring for callable instances, then constructor docstring for classes, then main object’s docstring otherwise (regular functions).
-
xonsh.inspectors.
find_file
(obj)[source]¶ Find the absolute path to the file where an object was defined.
This is essentially a robust wrapper around inspect.getabsfile.
Returns None if no file can be found.
Parameters: obj : any Python object
Returns: fname : str
The absolute path to the file where the object was defined.
-
xonsh.inspectors.
find_source_lines
(obj)[source]¶ Find the line number in a file where an object was defined.
This is essentially a robust wrapper around inspect.getsourcelines.
Returns None if no file can be found.
Parameters: obj : any Python object
Returns: lineno : int
The line number where the object definition starts.
-
xonsh.inspectors.
format_argspec
(argspec)[source]¶ Format argspect, convenience wrapper around inspect’s.
This takes a dict instead of ordered arguments and calls inspect.format_argspec with the arguments in the necessary order.
-
xonsh.inspectors.
get_encoding
(obj)[source]¶ Get encoding for python source file defining obj
Returns None if obj is not defined in a sourcefile.
-
xonsh.inspectors.
getargspec
(obj)[source]¶ Wrapper around
inspect.getfullargspec()
on Python 3, and :func:inspect.getargspec` on Python 2.In addition to functions and methods, this can also handle objects with a
__call__
attribute.
-
xonsh.inspectors.
getdoc
(obj)[source]¶ Stable wrapper around inspect.getdoc.
This can’t crash because of attribute problems.
It also attempts to call a getdoc() method on the given object. This allows objects which provide their docstrings via non-standard mechanisms (like Pyro proxies) to still be inspected by ipython’s ? system.
-
xonsh.inspectors.
getsource
(obj, is_binary=False)[source]¶ Wrapper around inspect.getsource.
This can be modified by other projects to provide customized source extraction.
Inputs:
- obj: an object whose source code we will attempt to extract.
Optional inputs:
- is_binary: whether the object is known to come from a binary source. This implementation will skip returning any output for binary objects, but custom extractors may know how to meaningfully process them.