module documentation

Helpers for inspecting Python modules.

Unknown Field: copyright
Copyright 2007-2022 by the Sphinx team, see AUTHORS.
Unknown Field: license
BSD, see LICENSE for details.
Variable logger Undocumented
Variable memory​_address​_re Undocumented
Class ​Default​Value A simple wrapper for default value of the parameters of overload functions.
Class ​Type​Alias​Forward​Ref Pseudo typing class for autodoc_type_aliases.
Class ​Type​Alias​Module Pseudo module class for autodoc_type_aliases.
Class ​Type​Alias​Namespace Pseudo namespace class for autodoc_type_aliases.
Function ​_should​_unwrap Check the function should be unwrapped on getting signature.
Function evaluate​_signature Evaluate unresolved type annotations in a signature object.
Function getall Get __all__ attribute of the module as dict.
Function getannotations Get __annotations__ from given obj safely.
Function getargspec Like inspect.getfullargspec but supports bound methods, and wrapped methods.
Function getdoc Get the docstring for the object.
Function getglobals Get __globals__ from given obj safely.
Function getmro Get __mro__ from given obj safely.
Function getorigbases Get __orig_bases__ from obj safely.
Function getslots Get __slots__ attribute of the class as dict.
Function is​_builtin​_class​_method If attr_name is implemented at builtin class, return True.
Function is​_cython​_function​_or​_method Check if the object is a function or method in cython.
Function is​_singledispatch​_function Check if the object is singledispatch function.
Function is​_singledispatch​_method Check if the object is singledispatch method.
Function isabstractmethod Check if the object is an abstractmethod.
Function isasyncgenfunction Check if the object is async-gen function.
Function isattributedescriptor Check if the object is an attribute like descriptor.
Function isbuiltin Check if the object is builtin.
Function isclassmethod Check if the object is classmethod.
Function iscoroutinefunction Check if the object is coroutine-function.
Function isdescriptor Check if the object is some kind of descriptor.
Function isenumattribute Check if the object is attribute of enum.
Function isenumclass Check if the object is subclass of enum.
Function isfunction Check if the object is function.
Function isgenericalias Check if the object is GenericAlias.
Function is​New​Type Check the if object is a kind of NewType.
Function ispartial Check if the object is partial.
Function isproperty Check if the object is property.
Function isroutine Check is any kind of function or method.
Function isstaticmethod Check if the object is staticmethod.
Function object​_description A repr() implementation that returns text safe to use in reST context.
Function safe​_getattr A getattr() that turns all exceptions into AttributeErrors.
Function signature Return a Signature object for the given subject.
Function signature​_from​_ast Create a Signature object from AST node.
Function signature​_from​_str Create a Signature object from string.
Function stringify​_signature Stringify a Signature object.
Function unpartial Get an original object from partial object.
Function unwrap Get an original object from wrapped object (wrapped functions).
Function unwrap​_all Get an original object from wrapped object (unwrapping partials, wrapped functions, and other decorators).
logger =

Undocumented

memory_address_re =

Undocumented

def _should_unwrap(subject):
Check the function should be unwrapped on getting signature.
Parameters
subject:CallableUndocumented
Returns
boolUndocumented
def evaluate_signature(sig, globalns=None, localns=None):
Evaluate unresolved type annotations in a signature object.
Parameters
sig:inspect.SignatureUndocumented
globalns:DictUndocumented
localns:DictUndocumented
Returns
inspect.SignatureUndocumented
def getall(obj):

Get __all__ attribute of the module as dict.

Return None if given obj does not have __all__. Raises ValueError if given obj have invalid __all__.

Parameters
obj:AnyUndocumented
Returns
Optional[Sequence[str]]Undocumented
def getannotations(obj):
Get __annotations__ from given obj safely.
Parameters
obj:AnyUndocumented
Returns
Mapping[str, Any]Undocumented
def getargspec(func):
Like inspect.getfullargspec but supports bound methods, and wrapped methods.
Parameters
func:CallableUndocumented
Returns
AnyUndocumented
def getdoc(obj, attrgetter=safe_getattr, allow_inherited=False, cls=None, name=None):

Get the docstring for the object.

This tries to obtain the docstring for some kind of objects additionally:

  • partial functions
  • inherited docstring
  • inherited decorated methods
Parameters
obj:AnyUndocumented
attrgetter:CallableUndocumented
allow​_inherited:boolUndocumented
cls:AnyUndocumented
name:strUndocumented
Returns
strUndocumented
def getglobals(obj):
Get __globals__ from given obj safely.
Parameters
obj:AnyUndocumented
Returns
Mapping[str, Any]Undocumented
def getmro(obj):
Get __mro__ from given obj safely.
Parameters
obj:AnyUndocumented
Returns
Tuple[Type, ...]Undocumented
def getorigbases(obj):
Get __orig_bases__ from obj safely.
Parameters
obj:AnyUndocumented
Returns
Optional[Tuple[Any, ...]]Undocumented
def getslots(obj):

Get __slots__ attribute of the class as dict.

Return None if gienv obj does not have __slots__. Raises TypeError if given obj is not a class. Raises ValueError if given obj have invalid __slots__.

Parameters
obj:AnyUndocumented
Returns
Optional[Dict]Undocumented
def is_builtin_class_method(obj, attr_name):

If attr_name is implemented at builtin class, return True.

>>> is_builtin_class_method(int, '__init__')
True

Why this function needed? CPython implements int.__init__ by Descriptor but PyPy implements it by pure Python code.

Parameters
obj:AnyUndocumented
attr​_name:strUndocumented
Returns
boolUndocumented
def is_cython_function_or_method(obj):
Check if the object is a function or method in cython.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def is_singledispatch_function(obj):
Check if the object is singledispatch function.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def is_singledispatch_method(obj):
Check if the object is singledispatch method.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isabstractmethod(obj):
Check if the object is an abstractmethod.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isasyncgenfunction(obj):
Check if the object is async-gen function.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isattributedescriptor(obj):
Check if the object is an attribute like descriptor.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isbuiltin(obj):
Check if the object is builtin.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isclassmethod(obj, cls=None, name=None):
Check if the object is classmethod.
Parameters
obj:AnyUndocumented
cls:AnyUndocumented
name:strUndocumented
Returns
boolUndocumented
def iscoroutinefunction(obj):
Check if the object is coroutine-function.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isdescriptor(x):
Check if the object is some kind of descriptor.
Parameters
x:AnyUndocumented
Returns
boolUndocumented
def isenumattribute(x):
Check if the object is attribute of enum.
Parameters
x:AnyUndocumented
Returns
boolUndocumented
def isenumclass(x):
Check if the object is subclass of enum.
Parameters
x:AnyUndocumented
Returns
boolUndocumented
def isfunction(obj):
Check if the object is function.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isgenericalias(obj):
Check if the object is GenericAlias.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isNewType(obj):
Check the if object is a kind of NewType.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def ispartial(obj):
Check if the object is partial.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isproperty(obj):
Check if the object is property.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isroutine(obj):
Check is any kind of function or method.
Parameters
obj:AnyUndocumented
Returns
boolUndocumented
def isstaticmethod(obj, cls=None, name=None):
Check if the object is staticmethod.
Parameters
obj:AnyUndocumented
cls:AnyUndocumented
name:strUndocumented
Returns
boolUndocumented
def object_description(object):
A repr() implementation that returns text safe to use in reST context.
Parameters
object:AnyUndocumented
Returns
strUndocumented
def safe_getattr(obj, name, *defargs):
A getattr() that turns all exceptions into AttributeErrors.
Parameters
obj:AnyUndocumented
name:strUndocumented
*defargs:AnyUndocumented
Returns
AnyUndocumented
def signature(subject, bound_method=False, follow_wrapped=None, type_aliases={}):
Return a Signature object for the given subject.
Parameters
subject:CallableUndocumented
bound​_method:boolSpecify subject is a bound method or not
follow​_wrapped:boolSame as inspect.signature().
type​_aliases:DictUndocumented
Returns
inspect.SignatureUndocumented
def signature_from_ast(node, code=''):
Create a Signature object from AST node.
Parameters
node:ast.FunctionDefUndocumented
code:strUndocumented
Returns
inspect.SignatureUndocumented
def signature_from_str(signature):
Create a Signature object from string.
Parameters
signature:strUndocumented
Returns
inspect.SignatureUndocumented
def stringify_signature(sig, show_annotation=True, show_return_annotation=True, unqualified_typehints=False):
Stringify a Signature object.
Parameters
sig:inspect.SignatureUndocumented
show​_annotation:boolIf enabled, show annotations on the signature
show​_return​_annotation:boolIf enabled, show annotation of the return value
unqualified​_typehints:boolIf enabled, show annotations as unqualified (ex. io.StringIO -> StringIO)
Returns
strUndocumented
def unpartial(obj):

Get an original object from partial object.

This returns given object itself if not partial.

Parameters
obj:AnyUndocumented
Returns
AnyUndocumented
def unwrap(obj):
Get an original object from wrapped object (wrapped functions).
Parameters
obj:AnyUndocumented
Returns
AnyUndocumented
def unwrap_all(obj, *, stop=None):
Get an original object from wrapped object (unwrapping partials, wrapped functions, and other decorators).
Parameters
obj:AnyUndocumented
stop:CallableUndocumented
Returns
AnyUndocumented