module documentation

Tests for stubs. Verify that various things in stubs are consistent with how things behave at runtime.

Class Error No class docstring; 0/7 instance variable, 4/4 methods documented
Class Missing Marker object for things that are missing (from a stub or the runtime).
Class Signature No class docstring; 0/4 instance variable, 0/2 method, 1/3 static method documented
Exception StubtestFailure Undocumented
Function build_stubs Uses mypy to construct stub objects for the given modules.
Function get_allowlist_entries Undocumented
Function get_mypy_type_of_runtime_value Returns a mypy type object representing the type of ``runtime``.
Function get_stub Returns a stub object for the given module, if we've built one.
Function get_typeshed_stdlib_modules Returns a list of stdlib modules in typeshed (for current Python version).
Function is_probably_a_function Undocumented
Function is_probably_private Undocumented
Function is_read_only_property Undocumented
Function is_subtype_helper Checks whether ``left`` is a subtype of ``right``.
Function main Undocumented
Function maybe_strip_cls Undocumented
Function parse_options Undocumented
Function safe_inspect_signature Undocumented
Function silent_import_module Undocumented
Function test_module Tests a given module's stub against introspecting it at runtime.
Function test_stubs This is stubtest! It's time to test the stubs!
Function verify Entry point for comparing a stub to a runtime object.
Function verify_decorator Undocumented
Function verify_funcitem Undocumented
Function verify_mypyfile Undocumented
Function verify_none Undocumented
Function verify_overloadedfuncdef Undocumented
Function verify_paramspecexpr Undocumented
Function verify_typealias Undocumented
Function verify_typeinfo Undocumented
Function verify_typevarexpr Undocumented
Function verify_var Undocumented
Constant IGNORABLE_CLASS_DUNDERS Undocumented
Constant IGNORED_MODULE_DUNDERS Undocumented
Constant MISSING Undocumented
Type Variable T Undocumented
Type Alias MaybeMissing Undocumented
Class _Arguments Undocumented
Function _get_imported_symbol_names Retrieve the names in the global namespace which are known to be imported.
Function _resolve_funcitem_from_decorator Returns a FuncItem that corresponds to the output of the decorator.
Function _style Wrapper around mypy.util for fancy formatting.
Function _truncate Undocumented
Function _verify_abstract_status Undocumented
Function _verify_arg_default_value Checks whether argument default values are compatible.
Function _verify_arg_name Checks whether argument names match.
Function _verify_exported_names Undocumented
Function _verify_final Undocumented
Function _verify_metaclass Undocumented
Function _verify_readonly_property Undocumented
Function _verify_signature Undocumented
Function _verify_static_class_methods Undocumented
Constant _formatter Undocumented
Variable _all_stubs Undocumented
def build_stubs(modules: list[str], options: Options, find_submodules: bool = False) -> list[str]: (source)

Uses mypy to construct stub objects for the given modules. This sets global state that ``get_stub`` can access. Returns all modules we might want to check. If ``find_submodules`` is False, this is equal to ``modules``. :param modules: List of modules to build stubs for. :param options: Mypy options for finding and building stubs. :param find_submodules: Whether to attempt to find submodules of the given modules as well.

def get_allowlist_entries(allowlist_file: str) -> Iterator[str]: (source)

Undocumented

def get_mypy_type_of_runtime_value(runtime: Any) -> mypy.types.Type|None: (source)

Returns a mypy type object representing the type of ``runtime``. Returns None if we can't find something that works.

def get_stub(module: str) -> nodes.MypyFile|None: (source)

Returns a stub object for the given module, if we've built one.

def get_typeshed_stdlib_modules(custom_typeshed_dir: str|None, version_info: tuple[int, int]|None = None) -> list[str]: (source)

Returns a list of stdlib modules in typeshed (for current Python version).

def is_probably_a_function(runtime: Any) -> bool: (source)

Undocumented

def is_probably_private(name: str) -> bool: (source)

Undocumented

def is_read_only_property(runtime: object) -> bool: (source)

Undocumented

def is_subtype_helper(left: mypy.types.Type, right: mypy.types.Type) -> bool: (source)

Checks whether ``left`` is a subtype of ``right``.

def main() -> int: (source)

Undocumented

def maybe_strip_cls(name: str, args: list[nodes.Argument]) -> list[nodes.Argument]: (source)

Undocumented

def parse_options(args: list[str]) -> _Arguments: (source)

Undocumented

def safe_inspect_signature(runtime: Any) -> inspect.Signature|None: (source)

Undocumented

def silent_import_module(module_name: str) -> types.ModuleType: (source)

Undocumented

def test_module(module_name: str) -> Iterator[Error]: (source)

Tests a given module's stub against introspecting it at runtime. Requires the stub to have been built already, accomplished by a call to ``build_stubs``. :param module_name: The module to test

def test_stubs(args: _Arguments, use_builtins_fixtures: bool = False) -> int: (source)

This is stubtest! It's time to test the stubs!

@singledispatch
def verify(stub: MaybeMissing[nodes.Node], runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Entry point for comparing a stub to a runtime object. We use single dispatch based on the type of ``stub``. :param stub: The mypy node representing a part of the stub :param runtime: The runtime object corresponding to ``stub``

@verify.register(nodes.Decorator)
def verify_decorator(stub: nodes.Decorator, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.FuncItem)
def verify_funcitem(stub: nodes.FuncItem, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.MypyFile)
def verify_mypyfile(stub: nodes.MypyFile, runtime: MaybeMissing[types.ModuleType], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(Missing)
def verify_none(stub: Missing, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.OverloadedFuncDef)
def verify_overloadedfuncdef(stub: nodes.OverloadedFuncDef, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.ParamSpecExpr)
def verify_paramspecexpr(stub: nodes.ParamSpecExpr, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.TypeAlias)
def verify_typealias(stub: nodes.TypeAlias, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.TypeInfo)
def verify_typeinfo(stub: nodes.TypeInfo, runtime: MaybeMissing[type[Any]], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.TypeVarExpr)
def verify_typevarexpr(stub: nodes.TypeVarExpr, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

@verify.register(nodes.Var)
def verify_var(stub: nodes.Var, runtime: MaybeMissing[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

IGNORABLE_CLASS_DUNDERS = (source)

Undocumented

Value
frozenset(set(['__dict__',
               '__annotations__',
               '__text_signature__',
               '__weakref__',
               '__del__',
               '__hash__',
               '__getattr__',
...
IGNORED_MODULE_DUNDERS = (source)

Undocumented

Value
frozenset(set(['__file__',
               '__doc__',
               '__name__',
               '__builtins__',
               '__package__',
               '__cached__',
               '__loader__',
...

Undocumented

Value
Missing()

Undocumented

Value
TypeVar('T')
MaybeMissing: typing_extensions.TypeAlias = (source)

Undocumented

Value
Union[T, Missing]
def _get_imported_symbol_names(runtime: types.ModuleType) -> frozenset[str]|None: (source)

Retrieve the names in the global namespace which are known to be imported. 1). Use inspect to retrieve the source code of the module 2). Use symtable to parse the source and retrieve names that are known to be imported from other modules. If either of the above steps fails, return `None`. Note that if a set of names is returned, it won't include names imported via `from foo import *` imports.

def _resolve_funcitem_from_decorator(dec: nodes.OverloadPart) -> nodes.FuncItem|None: (source)

Returns a FuncItem that corresponds to the output of the decorator. Returns None if we can't figure out what that would be. For convenience, this function also accepts FuncItems.

def _style(message: str, **kwargs: Any) -> str: (source)

Wrapper around mypy.util for fancy formatting.

def _truncate(message: str, length: int) -> str: (source)

Undocumented

def _verify_abstract_status(stub: nodes.FuncDef, runtime: Any) -> Iterator[str]: (source)

Undocumented

def _verify_arg_default_value(stub_arg: nodes.Argument, runtime_arg: inspect.Parameter) -> Iterator[str]: (source)

Checks whether argument default values are compatible.

def _verify_arg_name(stub_arg: nodes.Argument, runtime_arg: inspect.Parameter, function_name: str) -> Iterator[str]: (source)

Checks whether argument names match.

def _verify_exported_names(object_path: list[str], stub: nodes.MypyFile, runtime_all_as_set: set[str]) -> Iterator[Error]: (source)

Undocumented

def _verify_final(stub: nodes.TypeInfo, runtime: type[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

def _verify_metaclass(stub: nodes.TypeInfo, runtime: type[Any], object_path: list[str]) -> Iterator[Error]: (source)

Undocumented

def _verify_readonly_property(stub: nodes.Decorator, runtime: Any) -> Iterator[str]: (source)

Undocumented

def _verify_signature(stub: Signature[nodes.Argument], runtime: Signature[inspect.Parameter], function_name: str) -> Iterator[str]: (source)

Undocumented

def _verify_static_class_methods(stub: nodes.FuncBase, runtime: Any, object_path: list[str]) -> Iterator[str]: (source)

Undocumented

Undocumented