MODULE

MKAPI.CORE.OBJECT

This module provides utility functions that relate to object.

Functions
function

mkapi.core.object.get_object(name) → any

Reutrns an object specified by name.

Parameters
  • name (str) Object name.
Examples
>>> import inspect
>>> obj = get_object('mkapi.core')
>>> inspect.ismodule(obj)
True
>>> obj = get_object('mkapi.core.base')
>>> inspect.ismodule(obj)
True
>>> obj = get_object('mkapi.core.node.Node')
>>> inspect.isclass(obj)
True
>>> obj = get_object('mkapi.core.node.Node.get_markdown')
>>> inspect.isfunction(obj)
True
function

mkapi.core.object.get_fullname(obj, name) → str

Reutrns an object full name specified by name.

Parameters
  • obj (any) Object that has a module.
  • name (str) Object name in the module.
Examples
>>> obj = get_object('mkapi.core.base.Item')
>>> get_fullname(obj, 'Section')
'mkapi.core.base.Section'
>>> get_fullname(obj, 'preprocess')
'mkapi.core.preprocess'
>>> get_fullname(obj, 'abc')
''
function

mkapi.core.object.split_prefix_and_name(obj) → (str, str)

Splits an object full name into prefix and name.

Parameters
  • obj (any) Object that has a module.
Examples
>>> import inspect
>>> obj = get_object('mkapi.core')
>>> split_prefix_and_name(obj)
('mkapi', 'core')
>>> obj = get_object('mkapi.core.base')
>>> split_prefix_and_name(obj)
('mkapi.core', 'base')
>>> obj = get_object('mkapi.core.node.Node')
>>> split_prefix_and_name(obj)
('mkapi.core.node', 'Node')
>>> obj = get_object('mkapi.core.node.Node.get_markdown')
>>> split_prefix_and_name(obj)
('mkapi.core.node.Node', 'get_markdown')
function

mkapi.core.object.get_sourcefiles(obj) → list of str

Returns a list of source file.

If obj is a class, source files of its superclasses are also included.

Parameters
  • obj (any) Object name.
function

mkapi.core.object.from_object(obj) → bool

Returns True, if the docstring of obj is the same as that of object.

Parameters
  • obj (any) Object.
  • name Object name.
Examples
>>> class A: pass
>>> from_object(A.__call__)
True
>>> from_object(A.__eq__)
True
>>> from_object(A.__getattribute__)
True
function

mkapi.core.object.get_origin(obj) → any

Returns an original object.

Parameters
  • obj (any)
Examples
>>> class A:
...    @property
...    def x(self):
...        pass
>>> hasattr(A.x, __name__)
False
>>> get_origin(A.x).__name__
'x'