module documentation
(source)

Stub generator for C modules.

The public interface is via the mypy.stubgen module.

Function add​_typing​_import Add typing imports for collections/types that occur in the generated stub.
Function generate​_c​_function​_stub Generate stub for a single function or method.
Function generate​_c​_property​_stub Generate property stub using introspection of 'obj'.
Function generate​_c​_type​_stub Generate stub for a single class using runtime introspection.
Function generate​_stub​_for​_c​_module Generate stub for C module.
Function get​_type​_fullname Undocumented
Function infer​_method​_sig Undocumented
Function is​_c​_classmethod Undocumented
Function is​_c​_function Undocumented
Function is​_c​_method Undocumented
Function is​_c​_property Undocumented
Function is​_c​_property​_readonly Undocumented
Function is​_c​_type Undocumented
Function is​_pybind11​_overloaded​_function​_docstring Undocumented
Function is​_pybind​_skipped​_attribute Undocumented
Function is​_skipped​_attribute Undocumented
Function is​_static​_property Undocumented
Function method​_name​_sort​_key Sort methods in classes in a typical order.
Function strip​_or​_import Strips unnecessary module names from typ.
Constant _DEFAULT​_TYPING​_IMPORTS Undocumented
def add_typing_import(output): (source)
Add typing imports for collections/types that occur in the generated stub.
Parameters
output:List[str]Undocumented
Returns
List[str]Undocumented
def generate_c_function_stub(module, name, obj, output, imports, self_var=None, sigs=None, class_name=None, class_sigs=None): (source)

Generate stub for a single function or method.

The result (always a single line) will be appended to 'output'. If necessary, any required names will be added to 'imports'. The 'class_name' is used to find signature of __init__ or __new__ in 'class_sigs'.

Parameters
module:ModuleTypeUndocumented
name:strUndocumented
obj:objectUndocumented
output:List[str]Undocumented
imports:List[str]Undocumented
self​_var:Optional[str]Undocumented
sigs:Optional[Dict[str, str]]Undocumented
class​_name:Optional[str]Undocumented
class​_sigs:Optional[Dict[str, str]]Undocumented
def generate_c_property_stub(name, obj, static_properties, rw_properties, ro_properties, readonly, module=None, imports=None): (source)

Generate property stub using introspection of 'obj'.

Try to infer type from docstring, append resulting lines to 'output'.

Parameters
name:strUndocumented
obj:objectUndocumented
static​_properties:List[str]Undocumented
rw​_properties:List[str]Undocumented
ro​_properties:List[str]Undocumented
readonly:boolUndocumented
module:Optional[ModuleType]Undocumented
imports:Optional[List[str]]Undocumented
def generate_c_type_stub(module, class_name, obj, output, imports, sigs=None, class_sigs=None): (source)

Generate stub for a single class using runtime introspection.

The result lines will be appended to 'output'. If necessary, any required names will be added to 'imports'.

Parameters
module:ModuleTypeUndocumented
class​_name:strUndocumented
obj:typeUndocumented
output:List[str]Undocumented
imports:List[str]Undocumented
sigs:Optional[Dict[str, str]]Undocumented
class​_sigs:Optional[Dict[str, str]]Undocumented
def generate_stub_for_c_module(module_name, target, sigs=None, class_sigs=None): (source)

Generate stub for C module.

This combines simple runtime introspection (looking for docstrings and attributes with simple builtin types) and signatures inferred from .rst documentation (if given).

If directory for target doesn't exist it will be created. Existing stub will be overwritten.

Parameters
module​_name:strUndocumented
target:strUndocumented
sigs:Optional[Dict[str, str]]Undocumented
class​_sigs:Optional[Dict[str, str]]Undocumented
def get_type_fullname(typ): (source)

Undocumented

Parameters
typ:typeUndocumented
Returns
strUndocumented
def infer_method_sig(name, self_var=None): (source)

Undocumented

Parameters
name:strUndocumented
self​_var:Optional[str]Undocumented
Returns
List[ArgSig]Undocumented
def is_c_classmethod(obj): (source)

Undocumented

Parameters
obj:objectUndocumented
Returns
boolUndocumented
def is_c_function(obj): (source)

Undocumented

Parameters
obj:objectUndocumented
Returns
boolUndocumented
def is_c_method(obj): (source)

Undocumented

Parameters
obj:objectUndocumented
Returns
boolUndocumented
def is_c_property(obj): (source)

Undocumented

Parameters
obj:objectUndocumented
Returns
boolUndocumented
def is_c_property_readonly(prop): (source)

Undocumented

Parameters
prop:AnyUndocumented
Returns
boolUndocumented
def is_c_type(obj): (source)

Undocumented

Parameters
obj:objectUndocumented
Returns
boolUndocumented
def is_pybind11_overloaded_function_docstring(docstr, name): (source)

Undocumented

Parameters
docstr:strUndocumented
name:strUndocumented
Returns
boolUndocumented
def is_pybind_skipped_attribute(attr): (source)

Undocumented

Parameters
attr:strUndocumented
Returns
boolUndocumented
def is_skipped_attribute(attr): (source)

Undocumented

Parameters
attr:strUndocumented
Returns
boolUndocumented
def is_static_property(obj): (source)

Undocumented

Parameters
obj:objectUndocumented
Returns
boolUndocumented
def method_name_sort_key(name): (source)

Sort methods in classes in a typical order.

I.e.: constructor, normal methods, special methods.

Parameters
name:strUndocumented
Returns
Tuple[int, str]Undocumented
def strip_or_import(typ, module, imports): (source)

Strips unnecessary module names from typ.

If typ represents a type that is inside module or is a type coming from builtins, remove module declaration from it. Return stripped name of the type.

Arguments:
typ: name of the type module: in which this type is used imports: list of import statements (may be modified during the call)
Parameters
typ:strUndocumented
module:ModuleTypeUndocumented
imports:List[str]Undocumented
Returns
strUndocumented
_DEFAULT_TYPING_IMPORTS: tuple[str, ...] = (source)

Undocumented

Value
('Any',
 'Callable',
 'ClassVar',
 'Dict',
 'Iterable',
 'Iterator',
 'List',
...