MODULE

MKAPI.CORE.SIGNATURE

This module provides Signature class that inspects object and creates signature and types.

Classes
Functions
  • a_of_b(annotation, obj) (str) Returns A of B style string.</>
  • resolve_forward_ref(obj, name) (str) Returns a resolved name for typing.ForwardRef.</>
  • to_string(annotation, kind, obj) (str) Returns string expression of annotation.</>
  • to_string_args(annotation, obj) (str) Returns a string for callable and generator annotation.</>
  • union(annotation, obj) (str) Returns a string for union annotation.</>
dataclass

mkapi.core.signature.Signature(obj=None)

Signature class.

Parameters
  • obj (any, optional) Object
Attributes
  • arguments (list of str, optional) Returns arguments list.</>
  • attributes (Section) Attributes section.
  • defaults (dict(str: any)) Default value dictionary. Key is parameter name and value is default value.
  • obj (any) Object
  • parameters (Section) Parameters section.
  • returns (str) Returned type string. Used in Returns section.
  • signature (Signature, optional) inspect.Signature instance.
  • yields (str) Yielded type string. Used in Yields section.
Methods
method

set_attributes()

Examples
>>> from mkapi.core.base import Base
>>> s = Signature(Base)
>>> s.parameters['name'].to_tuple()
('name', 'str, optional', 'Name of self.')
>>> s.attributes['html'].to_tuple()
('html', 'str', 'HTML output after conversion.')
function

mkapi.core.signature.to_string(annotation, kind='returns', obj=None) → str

Returns string expression of annotation.

If possible, type string includes link.

Parameters
  • annotation Annotation
  • kind (str, optional) 'returns' or 'yields'
  • obj (optional)
Examples
>>> from typing import Callable, Iterator, List
>>> to_string(Iterator[str])
'iterator of str'
>>> to_string(Iterator[str], 'yields')
'str'
>>> to_string(Callable)
'callable'
>>> to_string(Callable[[int, float], str])
'callable(int, float: str)'
>>> from mkapi.core.node import Node
>>> to_string(List[Node])
'list of [Node](!mkapi.core.node.Node)'
function

mkapi.core.signature.a_of_b(annotation, obj=None) → str

Returns A of B style string.

Parameters
  • annotation Annotation
  • obj (optional)
Examples
>>> from typing import List, Iterable, Iterator
>>> a_of_b(List[str])
'list of str'
>>> a_of_b(List[List[str]])
'list of list of str'
>>> a_of_b(Iterable[int])
'iterable of int'
>>> a_of_b(Iterator[float])
'iterator of float'
function

mkapi.core.signature.union(annotation, obj=None) → str

Returns a string for union annotation.

Parameters
  • annotation Annotation
  • obj (optional)
Examples
>>> from typing import List, Optional, Tuple, Union
>>> union(Optional[List[str]])
'list of str, optional'
>>> union(Union[str, int])
'str or int'
>>> union(Union[str, int, float])
'str, int, or float'
>>> union(Union[List[str], Tuple[int, int]])
'Union(list of str, (int, int))'
function

mkapi.core.signature.to_string_args(annotation, obj=None) → str

Returns a string for callable and generator annotation.

Parameters
  • annotation Annotation
  • obj (optional)
Examples
>>> from typing import Callable, List, Tuple, Any
>>> from typing import Generator, AsyncGenerator
>>> to_string_args(Callable[[int, List[str]], Tuple[int, int]])
'callable(int, list of str: (int, int))'
>>> to_string_args(Callable[[int], Any])
'callable(int)'
>>> to_string_args(Callable[[str], None])
'callable(str)'
>>> to_string_args(Callable[..., int])
'callable(...: int)'
>>> to_string_args(Generator[int, float, str])
'generator(int, float, str)'
>>> to_string_args(AsyncGenerator[int, float])
'asyncgenerator(int, float)'
function

mkapi.core.signature.resolve_forward_ref(obj, name) → str

Returns a resolved name for typing.ForwardRef.

Parameters
  • obj (any) Object
  • name (str) Forward reference name.
Examples
>>> from mkapi.core.base import Docstring
>>> resolve_forward_ref(Docstring, 'Docstring')
'[Docstring](!mkapi.core.base.Docstring)'
>>> resolve_forward_ref(Docstring, 'invalid_object_name')
'invalid_object_name'