Important

This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: core.oinspect

Tools for inspecting Python objects.

Uses syntax highlighting for presenting the various information elements.

Similar in spirit to the inspect module, but all calls take a name argument to reference the name under which an object is being read.

4 Classes

class IPython.core.oinspect.OInfo(ismagic: bool, isalias: bool, found: bool, namespace: str | None, parent: Any, obj: Any)

Bases: object

get(field)

Get a field from the object for backward compatibility with before 8.12

see https://github.com/h5py/h5py/issues/2253

class IPython.core.oinspect.InfoDict

Bases: TypedDict

class IPython.core.oinspect.InspectorHookData(obj: Any, info: OInfo | None, info_dict: InfoDict, detail_level: int, omit_sections: list[str])

Bases: object

Data passed to the mime hook

class IPython.core.oinspect.Inspector(**kwargs: Any)

Bases: Colorable

__init__(color_table={'': <IPython.utils.coloransi.ColorScheme object>, 'LightBG': <IPython.utils.coloransi.ColorScheme object>, 'Linux': <IPython.utils.coloransi.ColorScheme object>, 'Neutral': <IPython.utils.coloransi.ColorScheme object>, 'NoColor': <IPython.utils.coloransi.ColorScheme object>}, code_color_table={'': <IPython.utils.coloransi.ColorScheme object>, 'LightBG': <IPython.utils.coloransi.ColorScheme object>, 'Linux': <IPython.utils.coloransi.ColorScheme object>, 'Neutral': <IPython.utils.coloransi.ColorScheme object>, 'NoColor': <IPython.utils.coloransi.ColorScheme object>}, scheme=None, str_detail_level=0, parent=None, config=None)

Create a configurable given a config config.

Parameters:
  • config (Config) – If this is empty, default values are used. If config is a Config instance, it will be used to configure the instance.

  • parent (Configurable instance, optional) – The parent Configurable instance of this object.

Notes

Subclasses of Configurable must call the __init__() method of Configurable before doing anything else and using super():

class MyConfigurable(Configurable):
    def __init__(self, config=None):
        super(MyConfigurable, self).__init__(config=config)
        # Then any other code you need to finish initialization.

This ensures that instances will be configured properly.

format_mime(bundle: Dict[str, List[Tuple[str, str]]]) Dict[str, str]

Format a mimebundle being created by _make_info_unformatted into a real mimebundle

info(obj, oname='', info=None, detail_level=0) InfoDict

Compute a dict with detailed information about an object.

Parameters:
  • obj (any) – An object to find information about

  • oname (str (default: '')) – Name of the variable pointing to obj.

  • info ((default: None)) – A struct (dict like with attr access) with some information fields which may have been precomputed already.

  • detail_level (int (default:0)) – If set to 1, more information is given.

Return type:

An object info dict with known fields from info_fields (see InfoDict).

mime_hooks

dictionary of mime to callable to add information into help mimebundle dict

noinfo(msg, oname)

Generic message when no information is found.

pdef(obj, oname='')

Print the call signature for any callable object.

If the object is a class, print the constructor information.

pdoc(obj, oname='', formatter=None)

Print the docstring for any object.

Optional: -formatter: a function to run the docstring through for specially formatted docstrings.

Examples

In [1]: class NoInit:

…: pass

In [2]: class NoDoc:

…: def __init__(self): …: pass

In [3]: %pdoc NoDoc No documentation found for NoDoc

In [4]: %pdoc NoInit No documentation found for NoInit

In [5]: obj = NoInit()

In [6]: %pdoc obj No documentation found for obj

In [5]: obj2 = NoDoc()

In [6]: %pdoc obj2 No documentation found for obj2

pfile(obj, oname='')

Show the whole file where an object was defined.

pinfo(obj, oname='', formatter=None, info: OInfo | None = None, detail_level=0, enable_html_pager=True, omit_sections=())

Show detailed information about an object.

Optional arguments:

  • oname: name of the variable pointing to the object.

  • formatter: callable (optional)

    A special formatter for docstrings.

    The formatter is a callable that takes a string as an input and returns either a formatted string or a mime type bundle in the form of a dictionary.

    Although the support of custom formatter returning a string instead of a mime type bundle is deprecated.

  • info: a structure with some information fields which may have been precomputed already.

  • detail_level: if set to 1, more information is given.

  • omit_sections: set of section keys and titles to omit

psearch(pattern, ns_table, ns_search=[], ignore_case=False, show_all=False, *, list_types=False)

Search namespaces with wildcards for objects.

Arguments:

  • pattern: string containing shell-like wildcards to use in namespace searches and optionally a type specification to narrow the search to objects of that type.

  • ns_table: dict of name->namespaces for search.

Optional arguments:

  • ns_search: list of namespace names to include in search.

  • ignore_case(False): make the search case-insensitive.

  • show_all(False): show all names, including those starting with underscores.

  • list_types(False): list all available object types for object matching.

psource(obj, oname='')

Print the source code for an object.

7 Functions

IPython.core.oinspect.pylight(code)
IPython.core.oinspect.get_encoding(obj)

Get encoding for python source file defining obj

Returns None if obj is not defined in a sourcefile.

IPython.core.oinspect.getdoc(obj) str | None

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.

IPython.core.oinspect.getsource(obj, oname='') str | None

Wrapper around inspect.getsource.

This can be modified by other projects to provide customized source extraction.

Parameters:
  • obj (object) – an object whose source code we will attempt to extract

  • oname (str) – (optional) a name under which the object is known

Returns:

src

Return type:

unicode or None

IPython.core.oinspect.is_simple_callable(obj)

True if obj is a function ()

IPython.core.oinspect.find_file(obj) str | None

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 – The absolute path to the file where the object was defined.

Return type:

str

IPython.core.oinspect.find_source_lines(obj)

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 – The line number where the object definition starts.

Return type:

int