module documentation
(source)

Tests for stubs.

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

Class ​Error No class docstring; 0/6 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
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​_dunder Returns whether name is a dunder name.
Function is​_probably​_a​_function 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 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​_typealias Undocumented
Function verify​_typeinfo Undocumented
Function verify​_typevarexpr Undocumented
Function verify​_var Undocumented
Constant MISSING Undocumented
Constant SPECIAL​_DUNDERS Undocumented
Constant T Undocumented
Variable ​Maybe​Missing Undocumented
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 _verify​_arg​_default​_value Checks whether argument default values are compatible.
Function _verify​_arg​_name Checks whether argument names match.
Function _verify​_property Undocumented
Function _verify​_signature Undocumented
Function _verify​_static​_class​_methods Undocumented
Variable _all​_stubs Undocumented
Variable _formatter Undocumented
def build_stubs(modules, options, find_submodules=False): (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.

Parameters
modules:List[str]List of modules to build stubs for.
options:OptionsMypy options for finding and building stubs.
find​_submodules:boolWhether to attempt to find submodules of the given modules as well.
Returns
List[str]Undocumented
def get_allowlist_entries(allowlist_file): (source)

Undocumented

Parameters
allowlist​_file:strUndocumented
Returns
Iterator[str]Undocumented
def get_mypy_type_of_runtime_value(runtime): (source)

Returns a mypy type object representing the type of runtime.

Returns None if we can't find something that works.

Parameters
runtime:AnyUndocumented
Returns
Optional[mypy.types.Type]Undocumented
def get_stub(module): (source)
Returns a stub object for the given module, if we've built one.
Parameters
module:strUndocumented
Returns
Optional[nodes.MypyFile]Undocumented
def get_typeshed_stdlib_modules(custom_typeshed_dir): (source)
Returns a list of stdlib modules in typeshed (for current Python version).
Parameters
custom​_typeshed​_dir:Optional[str]Undocumented
Returns
List[str]Undocumented
def is_dunder(name, exclude_special=False): (source)
Returns whether name is a dunder name.
Parameters
name:strUndocumented
exclude​_special:boolWhether to return False for a couple special dunder methods.
Returns
boolUndocumented
def is_probably_a_function(runtime): (source)

Undocumented

Parameters
runtime:AnyUndocumented
Returns
boolUndocumented
def is_subtype_helper(left, right): (source)
Checks whether left is a subtype of right.
Parameters
left:mypy.types.TypeUndocumented
right:mypy.types.TypeUndocumented
Returns
boolUndocumented
def main(): (source)

Undocumented

Returns
intUndocumented
def maybe_strip_cls(name, args): (source)

Undocumented

Parameters
name:strUndocumented
args:List[nodes.Argument]Undocumented
Returns
List[nodes.Argument]Undocumented
def parse_options(args): (source)

Undocumented

Parameters
args:List[str]Undocumented
Returns
argparse.NamespaceUndocumented
def safe_inspect_signature(runtime): (source)

Undocumented

Parameters
runtime:AnyUndocumented
Returns
Optional[inspect.Signature]Undocumented
def test_module(module_name): (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.

Parameters
module​_name:strThe module to test
Returns
Iterator[Error]Undocumented
def test_stubs(args, use_builtins_fixtures=False): (source)
This is stubtest! It's time to test the stubs!
Parameters
args:argparse.NamespaceUndocumented
use​_builtins​_fixtures:boolUndocumented
Returns
intUndocumented
@singledispatch
def verify(stub, runtime, object_path): (source)

Entry point for comparing a stub to a runtime object.

We use single dispatch based on the type of stub.

Parameters
stub:MaybeMissing[nodes.Node]The mypy node representing a part of the stub
runtime:MaybeMissing[Any]The runtime object corresponding to stub
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.Decorator)
def verify_decorator(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.DecoratorUndocumented
runtime:MaybeMissing[Any]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.FuncItem)
def verify_funcitem(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.FuncItemUndocumented
runtime:MaybeMissing[Any]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.MypyFile)
def verify_mypyfile(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.MypyFileUndocumented
runtime:MaybeMissing[types.ModuleType]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(Missing)
def verify_none(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:MissingUndocumented
runtime:MaybeMissing[Any]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.OverloadedFuncDef)
def verify_overloadedfuncdef(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.OverloadedFuncDefUndocumented
runtime:MaybeMissing[Any]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.TypeAlias)
def verify_typealias(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.TypeAliasUndocumented
runtime:MaybeMissing[Any]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.TypeInfo)
def verify_typeinfo(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.TypeInfoUndocumented
runtime:MaybeMissing[Type[Any]]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.TypeVarExpr)
def verify_typevarexpr(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.TypeVarExprUndocumented
runtime:MaybeMissing[Any]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
@verify.register(nodes.Var)
def verify_var(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.VarUndocumented
runtime:MaybeMissing[Any]Undocumented
object​_path:List[str]Undocumented
Returns
Iterator[Error]Undocumented
MISSING = (source)

Undocumented

Value
Missing()
SPECIAL_DUNDERS: tuple[str, ...] = (source)

Undocumented

Value
('__init__', '__new__', '__call__', '__init_subclass__', '__class_getitem__')

Undocumented

Value
TypeVar('T')
MaybeMissing = (source)

Undocumented

def _resolve_funcitem_from_decorator(dec): (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.

Parameters
dec:nodes.OverloadPartUndocumented
Returns
Optional[nodes.FuncItem]Undocumented
def _style(message, **kwargs): (source)
Wrapper around mypy.util for fancy formatting.
Parameters
message:strUndocumented
**kwargs:AnyUndocumented
Returns
strUndocumented
def _verify_arg_default_value(stub_arg, runtime_arg): (source)
Checks whether argument default values are compatible.
Parameters
stub​_arg:nodes.ArgumentUndocumented
runtime​_arg:inspect.ParameterUndocumented
Returns
Iterator[str]Undocumented
def _verify_arg_name(stub_arg, runtime_arg, function_name): (source)
Checks whether argument names match.
Parameters
stub​_arg:nodes.ArgumentUndocumented
runtime​_arg:inspect.ParameterUndocumented
function​_name:strUndocumented
Returns
Iterator[str]Undocumented
def _verify_property(stub, runtime): (source)

Undocumented

Parameters
stub:nodes.DecoratorUndocumented
runtime:AnyUndocumented
Returns
Iterator[str]Undocumented
def _verify_signature(stub, runtime, function_name): (source)

Undocumented

Parameters
stub:Signature[nodes.Argument]Undocumented
runtime:Signature[inspect.Parameter]Undocumented
function​_name:strUndocumented
Returns
Iterator[str]Undocumented
def _verify_static_class_methods(stub, runtime, object_path): (source)

Undocumented

Parameters
stub:nodes.FuncBaseUndocumented
runtime:AnyUndocumented
object​_path:List[str]Undocumented
Returns
Iterator[str]Undocumented
_all_stubs: Dict[str, nodes.MypyFile] = (source)

Undocumented

_formatter = (source)

Undocumented