module documentation

Stub generator for C modules. The public interface is via the mypy.stubgen module.

Class DocstringSignatureGenerator Undocumented
Class ExternalSignatureGenerator No class docstring; 0/2 instance variable, 1/3 method documented
Class FallbackSignatureGenerator Undocumented
Class SignatureGenerator Abstract base class for extracting a list of FunctionSigs for each function.
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: list[str]) -> list[str]: (source)

Add typing imports for collections/types that occur in the generated stub.

def generate_c_function_stub(module: ModuleType, name: str, obj: object, output: list[str], imports: list[str], sig_generators: Iterable[SignatureGenerator], self_var: str|None = None, class_name: str|None = 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'.

def generate_c_property_stub(name: str, obj: object, static_properties: list[str], rw_properties: list[str], ro_properties: list[str], readonly: bool, module: ModuleType|None = None, imports: list[str]|None = None): (source)

Generate property stub using introspection of 'obj'. Try to infer type from docstring, append resulting lines to 'output'.

def generate_c_type_stub(module: ModuleType, class_name: str, obj: type, output: list[str], imports: list[str], sig_generators: Iterable[SignatureGenerator]): (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'.

def generate_stub_for_c_module(module_name: str, target: str, sig_generators: Iterable[SignatureGenerator]): (source)

Generate stub for C module. Signature generators are called in order until a list of signatures is returned. The order is: - signatures inferred from .rst documentation (if given) - simple runtime introspection (looking for docstrings and attributes with simple builtin types) - fallback based special method names or "(*args, **kwargs)" If directory for target doesn't exist it will be created. Existing stub will be overwritten.

def get_type_fullname(typ: type) -> str: (source)

Undocumented

def infer_method_sig(name: str, self_var: str|None = None) -> list[ArgSig]: (source)

Undocumented

def is_c_classmethod(obj: object) -> bool: (source)

Undocumented

def is_c_function(obj: object) -> bool: (source)

Undocumented

def is_c_method(obj: object) -> bool: (source)

Undocumented

def is_c_property(obj: object) -> bool: (source)

Undocumented

def is_c_property_readonly(prop: Any) -> bool: (source)

Undocumented

def is_c_type(obj: object) -> bool: (source)

Undocumented

def is_pybind11_overloaded_function_docstring(docstr: str, name: str) -> bool: (source)

Undocumented

def is_pybind_skipped_attribute(attr: str) -> bool: (source)

Undocumented

def is_skipped_attribute(attr: str) -> bool: (source)

Undocumented

def is_static_property(obj: object) -> bool: (source)

Undocumented

def method_name_sort_key(name: str) -> tuple[int, str]: (source)

Sort methods in classes in a typical order. I.e.: constructor, normal methods, special methods.

def strip_or_import(typ: str, module: ModuleType, imports: list[str]) -> str: (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)

_DEFAULT_TYPING_IMPORTS: tuple[str, ...] = (source)

Undocumented

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