mypy API reference
400 public APIs from mypy (python/mypy) — 92 classes, 165 functions, 143 methods. Signatures extracted by static analysis of the actual source.
Repository: python/mypy
| Kind | Count |
|---|---|
| Classes | 92 |
| Functions | 165 |
| Methods | 143 |
API list
func
misc.analyze_typeform_stats.analyze_stats(output:str) -> NoneParse mypy stats output and calculate TypeForm parsing efficiency.
func
misc.diff-cache.encode_for_diff(s:str, obj:object) -> strEncode a cache entry value for inclusion in the JSON diff.
func
misc.diff-cache.load(cache:MetadataStore, s:str) -> AnyLoad and normalize a cache entry.
func
misc.diff-cache.normalize_json_meta(obj:dict[str, Any]) -> NoneNormalize a JSON meta dict to avoid spurious diffs.
func
misc.diff-cache.normalize_meta(meta:CacheMeta) -> NoneNormalize a CacheMeta instance to avoid spurious diffs.
func
misc.diff-cache.serialize_meta_ff(meta:CacheMeta, version_prefix:bytes) -> bytesSerialize a CacheMeta instance back to fixed format binary.
func
misc.sync-typeshed.update_typeshed(typeshed_dir:str, commit:str | None) -> strUpdate contents of local typeshed copy.
class
mypy.applytype.PolyTranslatorMake free type variables generic in the type if possible.
func
mypy.applytype.apply_poly(tp:CallableType, poly_tvars:Sequence[TypeVarLikeType]) -> CallableType | NoneMake free type variables generic in the type if possible.
class
mypy.binder.ConditionalTypeBinderKeep track of conditional types of variables.
method
mypy.binder.ConditionalTypeBinder.assign_type(expr:Expression, type:Type, declared_type:Type | None) -> NoneNarrow type of expression through an assignment.
method
mypy.binder.ConditionalTypeBinder.can_put_directly(expr:Expression) -> boolWill `.put()` on this expression be successful?
method
mypy.binder.ConditionalTypeBinder.cleanse(expr:Expression) -> NoneRemove all references to a Node from the binder.
method
mypy.binder.ConditionalTypeBinder.pop_frame(can_skip:bool, fall_through:int, *discard:bool=False) -> FramePop a frame and return it.
method
mypy.binder.ConditionalTypeBinder.push_frame(conditional_frame:bool=False) -> FramePush a new frame into the binder.
method
mypy.binder.ConditionalTypeBinder.put(expr:Expression, typ:Type, *from_assignment:bool=True) -> NoneDirectly set the narrowed type of expression (if it supports it).
class
mypy.binder.FrameA Frame represents a specific point in the execution of a program.
class
mypy.binder.FrameContextContext manager pushing a Frame to ConditionalTypeBinder.
func
mypy.binder.collapse_variadic_union(typ:UnionType) -> TypeSimplify a union involving variadic tuple if possible.
func
mypy.binder.get_declaration(expr:BindableExpression) -> Type | NoneGet the declared or inferred type of a RefExpr expression.
class
mypy.build.AckMessageAn empty message used primarily for synchronization.
class
mypy.build.BuildManagerThis class holds shared state for building a mypy program.
method
mypy.build.BuildManager.all_imported_modules_in_file(file:MypyFile) -> list[tuple[int, str, int]]Find all reachable import statements in a file.
method
mypy.build.BuildManager.broadcast(message:bytes) -> NoneBroadcast same message to all workers in parallel.
method
mypy.build.BuildManager.correct_rel_imp(file:MypyFile, imp:ImportFrom | ImportAll) -> strFunction to correct for relative imports.
method
mypy.build.BuildManager.get_scc_batch(max_size_in_batch:int) -> list[SCC]Get a batch of SCCs from queue to submit to a worker.
method
mypy.build.BuildManager.getmtime(path:str) -> intReturn a file's mtime; but 0 in bazel mode.
method
mypy.build.BuildManager.is_module(id:str) -> boolDoes the given fullname refer to a module?
method
mypy.build.BuildManager.is_transitive_scc_dep(from_scc_id:int, to_scc_id:int) -> boolCheck if one SCC is a (transitive) dependency of another.
method
mypy.build.BuildManager.parse_file(id:str, path:str, source:str | None, options:Options, raw_data:FileRawData | None=None) -> MypyFileParse the source of a file with the given name.
method
mypy.build.BuildManager.parse_files_threaded_raw(states:list[State]) -> tuple[list[State], set[State]]Parse files in parallel using a thread pool.
method
mypy.build.BuildManager.receive_worker_message(idx:int) -> ReadBufferReceive a single message from a worker, with crash diagnostics.
method
mypy.build.BuildManager.submit(graph:Graph, sccs:list[SCC]) -> NoneSubmit a stale SCC for processing in current process or parallel workers.
method
mypy.build.BuildManager.wait_ack() -> NoneWait for an ack from all workers.
method
mypy.build.BuildManager.wait_for_done(graph:Graph) -> tuple[list[SCC], bool, dict[str, ModuleResult]]Wait for a stale SCC processing to finish.
class
mypy.build.BuildResultThe result of a successful build.
class
mypy.build.GraphMessageA message wrapping the build graph computed by the coordinator.
class
mypy.build.ModuleNotFoundControl flow exception to signal that a module was not found.
class
mypy.build.NodeInfoSome info about a node in the graph of SCCs.
method
mypy.build.NodeInfo.dumps() -> strConvert to JSON string.
class
mypy.build.SccRequestMessageA message representing a request to type check a batch of SCCs.
class
mypy.build.SccsDataMessageA message wrapping the SCC structure computed by the coordinator.
class
mypy.build.SourcesDataMessageA message wrapping a list of build sources.
class
mypy.build.StateThe state for a module.
method
mypy.build.State.check_blockers() -> NoneRaise CompileError if a blocking error is detected.
method
mypy.build.State.compute_dependencies() -> NoneCompute a module's dependencies after parsing it.
method
mypy.build.State.get_source() -> strGet module source and parse inline mypy configurations.
method
mypy.build.State.is_fresh() -> boolReturn whether the cache data for this file is fresh.
method
mypy.build.State.parse_file(*temporary:bool=False, *raw_data:FileRawData | None=None) -> NoneParse file and run first pass of semantic analysis.
method
mypy.build.State.parse_inline_configuration(source:str) -> NoneCheck for inline mypy: options directive and parse them.
method
mypy.build.State.reload_meta() -> NoneForce reload of cache meta.
method
mypy.build.State.verify_dependencies(suppressed_only:bool=False) -> NoneReport errors for import targets in modules that don't exist.
method
mypy.build.State.wrap_context(check_blockers:bool=True) -> Iterator[None]Temporarily change the error import context to match this state.
method
mypy.build.State.write(buf:WriteBuffer) -> NoneSerialize State for sending to build worker.
class
mypy.build.WorkerClientA simple class that represents a mypy build worker.
func
mypy.build.add_catch_all_gitignore(target_dir:str) -> NoneAdd catch-all .gitignore to an existing directory.
func
mypy.build.create_metastore(options:Options, parallel_worker:bool) -> MetadataStoreCreate the appropriate metadata store.
func
mypy.build.default_data_dir() -> strReturns directory containing typeshed directory.
func
mypy.build.deps_filtered(graph:Graph, vertices:AbstractSet[str], id:str, pri_max:int) -> list[str]Filter dependencies for id with pri < pri_max.
func
mypy.build.dump_graph(graph:Graph, stdout:TextIO | None=None) -> NoneDump the graph as a JSON string to stdout.
func
mypy.build.dump_line_checking_stats(path:str, graph:Graph) -> NoneDump per-line expression type checking stats.
func
mypy.build.dump_timing_stats(path:str, graph:Graph) -> NoneDump timing stats for each file in the given graph.
func
mypy.build.find_cache_meta(id:str, path:str, manager:BuildManager, skip_validation:bool=False) -> tuple[CacheMeta, CacheMetaEx] | NoneFind cache data for a module.
func
mypy.build.find_module_simple(id:str, manager:BuildManager) -> str | NoneFind a filesystem path for module `id` or `None` if not found.
func
mypy.build.find_stale_sccs(sccs:list[SCC], graph:Graph, manager:BuildManager) -> tuple[list[SCC], list[SCC]]Split a list of ready SCCs into stale and fresh.
func
mypy.build.get_cache_names(id:str, path:str, options:Options) -> tuple[str, str, str | None]Return the file names for the cache files.
func
mypy.build.import_priority(imp:ImportBase, toplevel_priority:int) -> intCompute import priority from an import node.
func
mypy.build.in_partial_package(id:str, manager:BuildManager) -> boolCheck if a missing module can potentially be a part of a package.
func
mypy.build.load_plugins(options:Options, errors:Errors, stdout:TextIO, extra_plugins:Sequence[Plugin]) -> tuple[Plugin, dict[str, str]]Load all configured plugins.
func
mypy.build.load_plugins_from_config(options:Options, errors:Errors, stdout:TextIO) -> tuple[list[Plugin], dict[str, str]]Load all configured plugins.
func
mypy.build.log_configuration(manager:BuildManager, sources:list[BuildSource]) -> NoneOutput useful configuration information to LOG and TRACE
func
mypy.build.maybe_load_deps(graph:Graph, ascc:SCC, manager:BuildManager) -> NoneLoad any missing fresh modules needed to process a stale SCC
func
mypy.build.normpath(path:str, options:Options) -> strConvert path to absolute; but to relative in bazel mode.
func
mypy.build.options_snapshot(module:str, manager:BuildManager) -> dict[str, object]Make compact snapshot of options for a module.
func
mypy.build.order_ascc(graph:Graph, ascc:AbstractSet[str], pri_max:int=PRI_INDIRECT) -> list[str]Come up with the ideal processing order within an SCC.
func
mypy.build.order_ascc_ex(graph:Graph, ascc:SCC) -> list[str]Apply extra heuristics on top of order_ascc().
func
mypy.build.process_graph(graph:Graph, manager:BuildManager) -> NoneProcess everything in dependency order.
func
mypy.build.process_stale_scc(graph:Graph, ascc:SCC, manager:BuildManager) -> NoneProcess the modules in one SCC from source code.
func
mypy.build.read_deps_cache(manager:BuildManager, graph:Graph) -> dict[str, FgDepMeta] | NoneRead and validate the fine-grained dependencies cache.
func
mypy.build.record_missing_stub_packages(cache_dir:str, missing_stub_packages:set[str]) -> NoneWrite a file containing missing stub packages.
func
mypy.build.sorted_components(graph:Graph) -> list[SCC]Return the graph's SCCs, topologically sorted by dependencies.
func
mypy.build.take_module_snapshot(module:types.ModuleType) -> strTake plugin module snapshot by recording its version and hash.
func
mypy.build.transitive_dep_hash(scc:SCC, graph:Graph) -> bytesCompute stable snapshot of transitive import structure for given SCC.
func
mypy.build.write_deps_cache(rdeps:dict[str, dict[str, set[str]]], manager:BuildManager, graph:Graph) -> NoneWrite cache files for fine-grained dependencies.
func
mypy.build.write_plugins_snapshot(manager:BuildManager) -> NoneWrite snapshot of versions and hashes of currently active plugins.
func
mypy.build_worker.worker.serve(server:IPCServer, ctx:ServerContext) -> NoneMain server loop of the worker.
func
mypy.build_worker.worker.should_shutdown(buf:ReadBuffer, expected_tag:Tag) -> boolCheck if the message is a shutdown request.
class
mypy.cache.CacheMetaClass representing cache metadata for a module.
class
mypy.checkexpr.ExpressionCheckerExpression type checker.
method
mypy.checkexpr.ExpressionChecker.accept(node:Expression, type_context:Type | None=None, allow_none_return:bool=False, always_allow_any:bool=False, is_callee:bool=False) -> TypeType check a node in the given type context.
method
mypy.checkexpr.ExpressionChecker.analyze_external_member_access(member:str, base_type:Type, context:Context) -> TypeAnalyse member access that is external, i.e.
method
mypy.checkexpr.ExpressionChecker.analyze_ordinary_member_access(e:MemberExpr, is_lvalue:bool, rvalue:Expression | None=None) -> TypeAnalyse member expression or member lvalue.
method
mypy.checkexpr.ExpressionChecker.analyze_type_type_callee(item:ProperType, context:Context) -> TypeAnalyze the callee X in X(...) where X is Type[item].
method
mypy.checkexpr.ExpressionChecker.bool_type() -> InstanceReturn instance type 'bool'.
method
mypy.checkexpr.ExpressionChecker.check_boolean_op(e:OpExpr) -> TypeType check a boolean operation ('and' or 'or').
method
mypy.checkexpr.ExpressionChecker.check_call_expr_with_callee_type(callee_type:Type, e:CallExpr, callable_name:str | None, object_type:Type | None, member:str | None=None) -> TypeType check call expression.
method
mypy.checkexpr.ExpressionChecker.check_for_comp(e:GeneratorExpr | DictionaryComprehension) -> NoneCheck the for_comp part of comprehensions.
method
mypy.checkexpr.ExpressionChecker.check_list_multiply(e:OpExpr) -> TypeType check an expression of form '[...] * e'.
method
mypy.checkexpr.ExpressionChecker.concat_tuples(left:TupleType, right:TupleType) -> TupleTypeConcatenate two fixed length tuples.
method
mypy.checkexpr.ExpressionChecker.defn_returns_none(defn:SymbolNode | None) -> boolCheck if `defn` can _only_ return None.
method
mypy.checkexpr.ExpressionChecker.get_partial_self_var(expr:MemberExpr) -> Var | NoneGet variable node for a partial self attribute.
method
mypy.checkexpr.ExpressionChecker.infer_arg_types_in_empty_context(args:list[Expression]) -> list[Type]Infer argument expression types in an empty context.
method
mypy.checkexpr.ExpressionChecker.is_valid_keyword_var_arg(typ:Type) -> boolIs a type valid as a **kwargs argument?
method
mypy.checkexpr.ExpressionChecker.is_valid_var_arg(typ:Type) -> boolIs a type valid as a *args argument?
method
mypy.checkexpr.ExpressionChecker.named_type(name:str) -> InstanceReturn an instance type with type given by the name and no type arguments.
method
mypy.checkexpr.ExpressionChecker.object_type() -> InstanceReturn instance type 'object'.
method
mypy.checkexpr.ExpressionChecker.try_infer_partial_type(e:CallExpr) -> NoneTry to make partial type precise from a call.
method
mypy.checkexpr.ExpressionChecker.try_parse_as_type_expression(maybe_type_expr:Expression) -> Type | NoneTry to parse a value Expression as a type expression.
method
mypy.checkexpr.ExpressionChecker.type_overrides_set(exprs:Sequence[Expression], overrides:Sequence[Type]) -> Iterator[None]Set _temporary_ type overrides for given expressions.
method
mypy.checkexpr.ExpressionChecker.visit_bytes_expr(e:BytesExpr) -> TypeType check a bytes literal (trivial).
method
mypy.checkexpr.ExpressionChecker.visit_call_expr(e:CallExpr, allow_none_return:bool=False) -> TypeType check a call expression.
method
mypy.checkexpr.ExpressionChecker.visit_cast_expr(expr:CastExpr) -> TypeType check a cast expression.
method
mypy.checkexpr.ExpressionChecker.visit_comparison_expr(e:ComparisonExpr) -> TypeType check a comparison expression.
method
mypy.checkexpr.ExpressionChecker.visit_complex_expr(e:ComplexExpr) -> TypeType check a complex literal.
method
mypy.checkexpr.ExpressionChecker.visit_dict_expr(e:DictExpr) -> TypeType check a dict expression.
method
mypy.checkexpr.ExpressionChecker.visit_dictionary_comprehension(e:DictionaryComprehension) -> TypeType check a dictionary comprehension.
method
mypy.checkexpr.ExpressionChecker.visit_ellipsis(e:EllipsisExpr) -> TypeType check '...'.
method
mypy.checkexpr.ExpressionChecker.visit_float_expr(e:FloatExpr) -> TypeType check a float literal (trivial).
method
mypy.checkexpr.ExpressionChecker.visit_index_expr(e:IndexExpr) -> TypeType check an index expression (base[index]).
method
mypy.checkexpr.ExpressionChecker.visit_int_expr(e:IntExpr) -> TypeType check an integer literal (trivial).
method
mypy.checkexpr.ExpressionChecker.visit_lambda_expr(e:LambdaExpr) -> TypeType check lambda expression.
method
mypy.checkexpr.ExpressionChecker.visit_list_expr(e:ListExpr) -> TypeType check a list expression [...].
method
mypy.checkexpr.ExpressionChecker.visit_member_expr(e:MemberExpr, is_lvalue:bool=False) -> TypeVisit member expression (of form e.id).
method
mypy.checkexpr.ExpressionChecker.visit_name_expr(e:NameExpr) -> TypeType check a name expression.
method
mypy.checkexpr.ExpressionChecker.visit_op_expr(e:OpExpr) -> TypeType check a binary operator expression.
method
mypy.checkexpr.ExpressionChecker.visit_reveal_expr(expr:RevealExpr) -> TypeType check a reveal_type expression.
method
mypy.checkexpr.ExpressionChecker.visit_str_expr(e:StrExpr) -> TypeType check a string literal (trivial).
method
mypy.checkexpr.ExpressionChecker.visit_super_expr(e:SuperExpr) -> TypeType check a super expression (non-lvalue).
method
mypy.checkexpr.ExpressionChecker.visit_template_str_expr(e:TemplateStrExpr) -> TypeType check a template string expression (t-string).
method
mypy.checkexpr.ExpressionChecker.visit_tuple_expr(e:TupleExpr) -> TypeType check a tuple expression.
method
mypy.checkexpr.ExpressionChecker.visit_type_alias_expr(alias:TypeAliasExpr) -> TypeRight hand side of a type alias definition.
method
mypy.checkexpr.ExpressionChecker.visit_type_application(tapp:TypeApplication) -> TypeType check a type application (expr[type, ...]).
method
mypy.checkexpr.ExpressionChecker.visit_unary_expr(e:UnaryExpr) -> TypeType check an unary operation ('not', '-', '+' or '~').
class
mypy.checkexpr.HasErasedComponentsQueryVisitor for querying whether a type has an erased component.
func
mypy.checkexpr.has_any_type(t:Type, ignore_in_type_obj:bool=False) -> boolWhether t contains an Any type
func
mypy.checkexpr.has_bytes_component(typ:Type) -> boolIs this one of builtin byte types, or a union that contains it?
func
mypy.checkexpr.has_coroutine_decorator(t:Type) -> boolWhether t came from a function decorated with `@coroutine`.
func
mypy.checkexpr.is_async_def(t:Type) -> boolWhether t came from a function defined using `async def`.
func
mypy.checkexpr.is_expr_literal_type(node:Expression) -> boolReturns 'true' if the given node is a Literal
func
mypy.checkexpr.replace_callable_return_type(c:CallableType, new_ret_type:Type) -> CallableTypeReturn a copy of a callable type with a different return type.
func
mypy.checkexpr.try_getting_literal(typ:Type) -> ProperTypeIf possible, get a more precise literal type for a given type.
class
mypy.checkmember.MemberContextInformation and objects needed to type check attribute access.
func
mypy.checkmember.analyze_decorator_or_funcbase_access(defn:Decorator | FuncBase, itype:Instance, name:str, mx:MemberContext) -> TypeAnalyzes the type behind method access.
func
mypy.checkmember.analyze_descriptor_access(descriptor_type:Type, mx:MemberContext) -> TypeType check descriptor access.
func
mypy.checkmember.analyze_member_var_access(name:str, itype:Instance, info:TypeInfo, mx:MemberContext) -> TypeAnalyse attribute access that does not target a method.
func
mypy.checkmember.analyze_var(name:str, var:Var, itype:Instance, mx:MemberContext, *implicit:bool=False, *is_trivial_self:bool=False) -> TypeAnalyze access to an attribute via a Var node.
func
mypy.checkmember.has_operator(typ:Type, op_method:str) -> boolDoes type have operator with the given name?
func
mypy.checkmember.is_instance_var(var:Var) -> boolReturn if var is an instance variable according to PEP 526.
func
mypy.checkmember.may_be_awaitable_attribute(name:str, typ:Type, mx:MemberContext, override_info:TypeInfo | None=None) -> boolCheck if the given type has the attribute when awaited.
class
mypy.checkpattern.PatternCheckerPattern checker.
func
mypy.checkpattern.get_var(expr:Expression) -> VarWarning: this in only true for expressions captured by a match statement.
class
mypy.checkstrformat.StringFormatterCheckerString interpolation/formatter type checker.
method
mypy.checkstrformat.StringFormatterChecker.accept(expr:Expression, context:Type | None=None) -> TypeType check a node.
method
mypy.checkstrformat.StringFormatterChecker.auto_generate_keys(all_specs:list[ConversionSpecifier], ctx:Context) -> boolTranslate '{} {name} {}' to '{0} {name} {1}'.
func
mypy.checkstrformat.has_type_component(typ:Type, fullname:str) -> boolIs this a specific instance type, or a union that contains it?
class
mypy.config_parser.VersionTypeErrorProvide a fallback value if the Python version is unsupported.
func
mypy.config_parser.convert_to_boolean(value:Any | None) -> boolReturn a boolean value translating from other types if necessary.
func
mypy.config_parser.mypy_comments_to_config_map(line:str, template:Options) -> tuple[dict[str, str], list[str]]Rewrite the mypy comment syntax into ini file syntax.
func
mypy.config_parser.parse_config_file(options:Options, set_strict_flags:Callable[[], None], filename:str | None, stdout:TextIO | None=None, stderr:TextIO | None=None) -> NoneParse a config file into an Options object.
func
mypy.config_parser.split_directive(s:str) -> tuple[list[str], list[str]]Split s on commas, except during quoted sections.
class
mypy.constraints.ConstraintA representation of a type constraint.
class
mypy.constraints.ConstraintBuilderVisitorVisitor class for inferring type constraints.
func
mypy.constraints.any_constraints(options:list[list[Constraint] | None], *eager:bool) -> list[Constraint]Deduce what we can from a collection of constraint lists.
func
mypy.constraints.filter_satisfiable(option:list[Constraint] | None) -> list[Constraint] | NoneKeep only constraints that can possibly be satisfied.
func
mypy.constraints.find_matching_overload_item(overloaded:Overloaded, template:CallableType) -> CallableTypeDisambiguate overload item against a template.
func
mypy.constraints.infer_constraints(template:Type, actual:Type, direction:int, skip_neg_op:bool=False, erase_types:bool=True) -> list[Constraint]Infer type constraints.
func
mypy.constraints.is_similar_constraints(x:list[Constraint], y:list[Constraint]) -> boolCheck that two lists of constraints have similar structure.
func
mypy.constraints.merge_with_any(constraint:Constraint) -> ConstraintTransform a constraint target into a union with given Any type.
func
mypy.constraints.neg_op(op:int) -> intMap SubtypeOf to SupertypeOf and vice versa.
func
mypy.constraints.repack_callable_args(callable:CallableType, tuple_type:TypeInfo) -> list[Type]Present callable with star unpack in a normalized form.
func
mypy.copytype.copy_type(t:ProperType) -> ProperTypeCreate a shallow copy of a type.
func
mypy.dmypy.client.action(subparser:argparse.ArgumentParser) -> Callable[[ActionFunction], ActionFunction]Decorator to tie an action function to a subparser.
func
mypy.dmypy.client.check_output(response:dict[str, Any], verbose:bool, junit_xml:str | None, perf_stats_file:str | None) -> NonePrint the output from a check or recheck command.
func
mypy.dmypy.client.check_status(data:dict[str, Any]) -> tuple[int, str]Check if the process is alive.
func
mypy.dmypy.client.do_check(args:argparse.Namespace) -> NoneAsk the daemon to check a list of files.
func
mypy.dmypy.client.do_daemon(args:argparse.Namespace) -> NoneServe requests in the foreground.
func
mypy.dmypy.client.do_hang(args:argparse.Namespace) -> NoneHang for 100 seconds, as a debug hack.
func
mypy.dmypy.client.do_help(args:argparse.Namespace) -> NonePrint full help (same as dmypy --help).
func
mypy.dmypy.client.do_inspect(args:argparse.Namespace) -> NoneAsk daemon to print the type of an expression.
func
mypy.dmypy.client.do_kill(args:argparse.Namespace) -> NoneKill daemon process with SIGKILL.
func
mypy.dmypy.client.do_restart(args:argparse.Namespace) -> NoneRestart daemon (it may or may not be running; but not hanging).
func
mypy.dmypy.client.do_start(args:argparse.Namespace) -> NoneStart daemon (it must not already be running).
func
mypy.dmypy.client.do_status(args:argparse.Namespace) -> NonePrint daemon status.
func
mypy.dmypy.client.do_stop(args:argparse.Namespace) -> NoneStop daemon via a 'stop' request.
func
mypy.dmypy.client.do_suggest(args:argparse.Namespace) -> NoneAsk the daemon for a suggested signature.
func
mypy.dmypy.client.get_status(status_file:str) -> tuple[int, str]Read status file and check if the process is alive.
func
mypy.dmypy.client.is_running(status_file:str) -> boolCheck if the server is running cleanly
func
mypy.dmypy.client.main(argv:list[str]) -> NoneThe code is top-down.
func
mypy.dmypy.client.request(status_file:str, command:str, *timeout:int | None=None, **kwds:object) -> dict[str, Any]Send a request to the daemon.
func
mypy.dmypy.client.restart_server(args:argparse.Namespace, allow_sources:bool=False) -> NoneRestart daemon (it may or may not be running; but not hanging).
func
mypy.dmypy.client.start_server(args:argparse.Namespace, allow_sources:bool=False) -> NoneStart the server from command arguments and wait for it.
func
mypy.dmypy.client.wait_for_server(status_file:str, timeout:float=5.0) -> NoneWait until the server is up.
func
mypy.dmypy_os.alive(pid:int) -> boolIs the process alive?
func
mypy.dmypy_os.kill(pid:int) -> NoneKill the process.
method
mypy.dmypy_server.Server.check(sources:list[BuildSource], export_types:bool, is_tty:bool, terminal_width:int) -> dict[str, Any]Check using fine-grained incremental mode.
method
mypy.dmypy_server.Server.cmd_check(files:Sequence[str], export_types:bool, is_tty:bool, terminal_width:int) -> dict[str, object]Check a list of files.
method
mypy.dmypy_server.Server.cmd_hang() -> dict[str, object]Hang for 100 seconds, as a debug hack.
method
mypy.dmypy_server.Server.cmd_status(fswatcher_dump_file:str | None=None) -> dict[str, object]Return daemon status.
method
mypy.dmypy_server.Server.cmd_stop() -> dict[str, object]Stop daemon.
method
mypy.dmypy_server.Server.cmd_suggest(function:str, callsites:bool, **kwargs:Any) -> dict[str, object]Suggest a signature for a function.
method
mypy.dmypy_server.Server.direct_imports(module:tuple[str, str], graph:mypy.build.Graph) -> list[BuildSource]Return the direct imports of module not included in seen.
method
mypy.dmypy_server.Server.fine_grained_increment_follow_imports(sources:list[BuildSource], explicit_export_types:bool=False) -> list[str]Like fine_grained_increment, but follow imports.
method
mypy.dmypy_server.Server.following_imports() -> boolAre we following imports?
method
mypy.dmypy_server.Server.run_command(command:str, data:dict[str, object]) -> dict[str, object]Run a specific command from the registry.
method
mypy.dmypy_server.Server.serve() -> NoneServe requests, synchronously (no thread or fork).
func
mypy.dmypy_server.ignore_suppressed_imports(module:str) -> boolCan we skip looking for newly unsuppressed imports to module?
class
mypy.dmypy_util.WriteToConnHelper class to write to a connection instead of standard output.
func
mypy.dmypy_util.receive(connection:IPCBase) -> AnyReceive single JSON data frame from a connection.
func
mypy.dmypy_util.send(connection:IPCBase, data:Any) -> NoneSend data to a connection encoded and framed.
class
mypy.erasetype.TypeVarEraserImplementation of type erasure
func
mypy.erasetype.erase_type(typ:Type) -> ProperTypeErase any type variables from a type.
func
mypy.erasetype.replace_meta_vars(t:Type, target_type:Type) -> TypeReplace unification variables in a type with the target type.
func
mypy.erasetype.shallow_erase_type_for_equality(typ:Type) -> ProperTypeErase type variables from Instance's
class
mypy.error_formatter.JSONFormatterFormatter for basic JSON output format.
method
mypy.error_formatter.JSONFormatter.report_error(error:'MypyError') -> strPrints out the errors as simple, static JSON lines.
class
mypy.errors.CompileErrorException raised when there is a compile error.
class
mypy.errors.ErrorInfoRepresentation of a single error message.
class
mypy.errors.ErrorsContainer for compile errors.
method
mypy.errors.Errors.clear_errors_in_targets(path:str, targets:set[str]) -> NoneRemove errors in specific fine-grained targets within a file.
method
mypy.errors.Errors.current_target() -> str | NoneRetrieves the current target from the associated scope.
method
mypy.errors.Errors.file_messages(path:str) -> list[ErrorTuple]Return an error tuple list of new error messages from a given file.
method
mypy.errors.Errors.find_shadow_file_mapping(path:str) -> str | NoneReturn the shadow file path for a given source file path or None.
method
mypy.errors.Errors.format_messages(path:str, error_tuples:list[ErrorTuple], formatter:ErrorFormatter | None=None) -> list[str]Return a string list of new error messages from a given file.
method
mypy.errors.Errors.format_messages_default(error_tuples:list[ErrorTuple], source_lines:list[str] | None) -> list[str]Return a string list that represents the error messages.
method
mypy.errors.Errors.get_watchers() -> Iterator[ErrorWatcher]Yield the `ErrorWatcher` stack from top to bottom.
method
mypy.errors.Errors.import_context() -> list[tuple[str, int]]Return a copy of the import context.
method
mypy.errors.Errors.is_blockers() -> boolAre the any errors that are blockers?
method
mypy.errors.Errors.is_errors() -> boolAre there any generated messages?
method
mypy.errors.Errors.is_errors_for_file(file:str) -> boolAre there any errors for the given file?
method
mypy.errors.Errors.new_messages() -> list[str]Return a string list of new error messages.
method
mypy.errors.Errors.num_messages() -> intReturn the number of generated messages.
method
mypy.errors.Errors.prefer_simple_messages() -> boolShould we generate simple/fast error messages?
method
mypy.errors.Errors.raise_error(use_stdout:bool=True) -> NoReturnRaise a CompileError with the generated messages.
method
mypy.errors.Errors.render_messages(file:str, errors:list[ErrorInfo]) -> list[ErrorTuple]Translate the messages into a sequence of tuples.
method
mypy.errors.Errors.report_simple_error(file:str, line:int, message:str, code:ErrorCode | None) -> NoneGenerate a simple error in a module.
method
mypy.errors.Errors.set_file(file:str, module:str | None, options:Options, scope:Scope | None=None) -> NoneSet the path and module id of the current file.
method
mypy.errors.Errors.set_ignore_prefix(prefix:str) -> NoneSet path prefix that will be removed from all paths.
method
mypy.errors.Errors.set_import_context(ctx:list[tuple[str, int]]) -> NoneReplace the entire import context with a new value.
method
mypy.errors.Errors.sort_messages(errors:list[ErrorInfo]) -> list[ErrorInfo]Sort an array of error messages locally by line number.
method
mypy.errors.Errors.sort_within_context(errors:list[ErrorInfo]) -> list[ErrorInfo]For the same location decide which messages to show first/last.
method
mypy.errors.Errors.targets() -> set[str]Return a set of all targets that contain errors.
func
mypy.errors.remove_path_prefix(path:str, prefix:str | None) -> strIf path starts with prefix, return copy of path with the prefix removed.
func
mypy.errors.report_internal_error(err:Exception, file:str | None, line:int, errors:Errors | None, options:Options, stdout:TextIO | None=None, stderr:TextIO | None=None) -> NoReturnReport internal error and exit.
func
mypy.evalexpr.evaluate_expression(expr:mypy.nodes.Expression) -> objectEvaluate an expression at runtime.
class
mypy.expandtype.ExpandTypeVisitorVisitor that substitutes type variables with values.
method
mypy.expandtype.ExpandTypeVisitor.expand_type_list_with_unpack(typs:list[Type]) -> list[Type]Expands a list of types that has an unpack.
method
mypy.expandtype.ExpandTypeVisitor.expand_type_tuple_with_unpack(typs:tuple[Type, ...]) -> list[Type]Expands a tuple of types that has an unpack.
func
mypy.expandtype.freshen_function_type_vars(callee:F) -> FSubstitute fresh type variables for generic function type variables.
class
mypy.exprtotype.TypeTranslationErrorException raised when an expression is not valid as a type.
class
mypy.fastparse.FindAttributeAssignCheck if an AST contains attribute assignments (e.g.
class
mypy.fastparse.FindYieldCheck if an AST contains yields or yield froms.
func
mypy.fastparse.is_possible_trivial_body(s:list[Statement]) -> boolCould the statements form a "trivial" function body, such as 'pass'?
func
mypy.fastparse.parse(source:str | bytes, fnam:str, module:str | None, errors:Errors, options:Options | None=None) -> MypyFileParse a source file, without doing any semantic analysis.
func
mypy.fastparse.parse_type_ignore_tag(tag:str | None) -> list[str] | NoneParse optional "[code, ...]" tag after "# type: ignore".
func
mypy.find_sources.keyfunc(name:str) -> tuple[bool, int, str]Determines sort order for directory listing.
func
mypy.find_sources.module_join(parent:str, child:str) -> strJoin module ids, accounting for a possibly empty parent.
func
mypy.find_sources.strip_py(arg:str) -> str | NoneStrip a trailing .py or .pyi suffix.
func
mypy.freetree.free_tree(tree:MypyFile) -> NoneFree all the ASTs associated with a module.
method
mypy.fscache.FileSystemCache.flush() -> NoneStart another transaction and empty all caches.
method
mypy.fscache.FileSystemCache.init_under_package_root(path:str) -> boolIs this path an __init__.py under a package root?
method
mypy.fscache.FileSystemCache.isfile_case(path:str, prefix:str) -> boolReturn whether path exists and is a file.
class
mypy.fswatcher.FileSystemWatcherWatcher for file system changes among specific paths.
method
mypy.fswatcher.FileSystemWatcher.update_changed(remove:list[str], update:list[str]) -> AbstractSet[str]Alternative to find_changed() given explicit changes.
class
mypy.gclogger.GcLoggerContext manager to log GC stats and overall time.
func
mypy.git.git_revision(dir:str) -> bytesGet the SHA-1 of the HEAD of a git repository.
func
mypy.git.have_git() -> boolCan we run the git executable?
func
mypy.git.is_dirty(dir:str) -> boolCheck whether a git repository has uncommitted changes.
func
mypy.git.is_git_repo(dir:str) -> boolIs the given directory version-controlled with git?
class
mypy.graph_utils.topsortTopological sort using Kahn's algorithm.
class
mypy.indirection.TypeIndirectionVisitorReturns all module references within a particular type.
class
mypy.infer.ArgumentInferContextType argument inference context.
class
mypy.inspections.InspectionEngineEngine for locating and statically inspecting expressions.
method
mypy.inspections.InspectionEngine.collect_attrs(instances:list[Instance]) -> dict[TypeInfo, list[str]]Collect attributes from all union/typevar variants.
method
mypy.inspections.InspectionEngine.collect_nodes(expression:RefExpr) -> list[FuncBase | SymbolNode]Collect nodes that can be referred to by an expression.
method
mypy.inspections.InspectionEngine.expr_attrs(expression:Expression) -> tuple[str, bool]Format attributes that are valid for a given expression.
method
mypy.inspections.InspectionEngine.expr_type(expression:Expression) -> tuple[str, bool]Format type for an expression using current options.
method
mypy.inspections.InspectionEngine.expression_def(expression:Expression) -> tuple[str, bool]Find and format definition location for an expression.
method
mypy.inspections.InspectionEngine.find_module(file:str) -> tuple[State | None, dict[str, object]]Find module by path, or return a suitable error message.
method
mypy.inspections.InspectionEngine.get_attrs(location:str) -> dict[str, object]Get attributes of expression(s) at a location.
method
mypy.inspections.InspectionEngine.get_definition(location:str) -> dict[str, object]Get symbol definitions of expression(s) at a location.
method
mypy.inspections.InspectionEngine.get_type(location:str) -> dict[str, object]Get types of expression(s) at a location.
method
mypy.inspections.InspectionEngine.reload_module(state:State) -> NoneReload given module while temporary exporting types.
method
mypy.inspections.InspectionEngine.run_inspection(location:str, method:Callable[[Expression], tuple[str, bool]]) -> dict[str, object]Top-level logic to inspect expression(s) at a location.
func
mypy.inspections.expr_span(expr:Expression) -> strFormat expression span as in mypy error messages.
func
mypy.inspections.find_module_by_fullname(fullname:str, modules:dict[str, State]) -> State | NoneFind module by a node fullname.
func
mypy.inspections.find_node(name:str, info:TypeInfo) -> Var | FuncBase | NoneFind the node defining member 'name' in given TypeInfo.
func
mypy.inspections.get_instance_fallback(typ:ProperType) -> list[Instance]Returns the Instance fallback for this type if one exists or None.
class
mypy.ipc.BadStatusException raised when there is something wrong with the status file.
class
mypy.ipc.IPCBaseBase class for communication between the dmypy client and server.
method
mypy.ipc.IPCBase.frame_from_buffer() -> bytes | NoneReturn a full frame from the bytes we have in the buffer.
method
mypy.ipc.IPCBase.read_bytes(size:int=MAX_READ) -> bytesRead bytes from an IPC connection until we have a full frame.
method
mypy.ipc.IPCBase.write_bytes(data:bytes) -> NoneWrite to an IPC connection.
class
mypy.ipc.IPCClientThe client side of an IPC connection.
class
mypy.ipc.IPCExceptionException for IPC issues.
func
mypy.ipc.read_status(status_file:str) -> dict[str, object]Read status file.
func
mypy.ipc.ready_to_read(conns:Sequence[IPCBase], timeout:float | None=None) -> list[int]Wait until some connections are readable.
func
mypy.ipc.receive(connection:IPCBase) -> ReadBufferReceive single encoded IPCMessage frame from a connection.
func
mypy.ipc.send(connection:IPCBase, data:IPCMessage) -> NoneSend data to a connection encoded and framed.
class
mypy.join.TypeJoinVisitorImplementation of the least upper bound algorithm.
method
mypy.join.TypeJoinVisitor.join_tuples(s:TupleType, t:TupleType) -> list[Type] | NoneJoin two tuple types while handling variadic entries.
func
mypy.join.object_from_instance(instance:Instance) -> InstanceConstruct the type 'builtins.object' from an instance type.
func
mypy.literals.extract_var_from_literal_hash(key:Key) -> Var | NoneIf key refers to a Var node, return it.
func
mypy.literals.literal(e:Expression) -> intReturn the literal kind for an expression.
func
mypy.literals.literal_hash(e:Expression) -> Key | NoneGenerate a hashable, (mostly) opaque key for expressions supported by the binder.
func
mypy.lookup.lookup_fully_qualified(name:str, modules:dict[str, MypyFile], *raise_on_missing:bool=False) -> SymbolTableNode | NoneFind a symbol using it fully qualified name.
func
mypy.lookup.lookup_stdlib_typeinfo(fullname:str, modules:dict[str, MypyFile]) -> TypeInfoFind TypeInfo for a standard library type.
class
mypy.main.CapturableVersionActionSupplement CapturableArgumentParser to handle --version.
func
mypy.main.fail(msg:str, stderr:TextIO, options:Options) -> NoReturnFail with a serious error.
func
mypy.main.infer_python_executable(options:Options, special_opts:argparse.Namespace) -> NoneInfer the Python executable from the given version.
func
mypy.main.main(*args:list[str] | None=None, *stdout:TextIO=sys.stdout, *stderr:TextIO=sys.stderr, *clean_exit:bool=False) -> NoneMain entry point to the type checker.
func
mypy.main.process_cache_map(parser:argparse.ArgumentParser, special_opts:argparse.Namespace, options:Options) -> NoneValidate cache_map and copy into options.cache_map.
func
mypy.main.process_package_roots(fscache:FileSystemCache | None, parser:argparse.ArgumentParser, options:Options) -> NoneValidate and normalize package_root.
func
mypy.meet.adjust_tuple(left:ProperType, r:ProperType) -> TupleType | NoneFind out if `left` is a Tuple[A, ...], and adjust its length to `right`
func
mypy.meet.are_tuples_overlapping(left:Type, right:Type, is_overlapping:Callable[[Type, Type], bool]) -> boolReturns true if left and right are overlapping tuples.
func
mypy.meet.is_literal_in_union(x:ProperType, y:ProperType) -> boolReturn True if x is a Literal and y is an Union that includes x
func
mypy.meet.meet_types(s:Type, t:Type) -> ProperTypeReturn the greatest lower bound of two types.
func
mypy.meet.narrow_declared_type(declared:Type, narrowed:Type) -> TypeReturn the declared type narrowed down to another type.
func
mypy.meet.typed_dict_mapping_overlap(left:Type, right:Type, overlapping:Callable[[Type, Type], bool]) -> boolCheck if a TypedDict type is overlapping with a Mapping.
func
mypy.memprofile.collect_memory_stats() -> tuple[dict[str, int], dict[str, int]]Return stats about memory use.
func
mypy.memprofile.find_recursive_objects(objs:list[object]) -> NoneFind additional objects referenced by objs and append them to objs.
func
mypy.messages.capitalize(s:str) -> strCapitalize the first character of a string.
func
mypy.messages.format_type_distinctly(*options:Options, *bare:bool=False, *types:Type) -> tuple[str, ...]Jointly format types to distinct strings.
func
mypy.messages.ignore_last_known_values(t:UnionType) -> TypeThis will avoid types like str | str in error messages.
func
mypy.messages.make_inferred_type_note(context:Context, subtype:Type, supertype:Type, supertype_str:str) -> strExplain that the user may have forgotten to type a variable.
func
mypy.messages.pretty_callable(tp:CallableType, options:Options, skip_self:bool=False) -> strReturn a nice easily-readable representation of a callable type.
func
mypy.messages.quote_type_string(type_string:str) -> strQuotes a type representation for use in messages.
func
mypy.messages.strip_quotes(s:str) -> strStrip a double quote at the beginning and end of the string, if any.
class
mypy.metastore.MetadataStoreGeneric interface for metadata storage.
method
mypy.metastore.MetadataStore.close() -> NoneRelease any resources held by the backing store.
method
mypy.metastore.MetadataStore.commit() -> NoneIf the backing store requires a commit, do it.
method
mypy.metastore.MetadataStore.commit_path(name:str) -> NoneCommit changes related to a specific cache path.
method
mypy.metastore.MetadataStore.getmtime(name:str) -> floatRead the mtime of a metadata entry.
method
mypy.metastore.MetadataStore.read(name:str) -> bytesRead the contents of a metadata entry.
method
mypy.metastore.MetadataStore.remove(name:str) -> NoneDelete a metadata entry
method
mypy.metastore.MetadataStore.write(name:str, data:bytes, mtime:float | None=None) -> boolWrite a metadata entry.
class
mypy.mixedtraverser.MixedTraverserVisitorRecursive traversal of both Node and Type objects.
class
mypy.modulefinder.BuildSourceA single source file.
class
mypy.modulefinder.FindModuleCacheModule finder with integrated cache.
func
mypy.modulefinder.compute_search_paths(sources:list[BuildSource], options:Options, data_dir:str, alt_lib_path:str | None=None) -> SearchPathsCompute the search paths as specified in PEP 561.
func
mypy.modulefinder.default_lib_path(data_dir:str, pyversion:tuple[int, int], custom_typeshed_dir:str | None) -> list[str]Return default standard library search paths.
func
mypy.modulefinder.get_search_dirs(python_executable:str | None) -> tuple[list[str], list[str]]Find package directories for given python.
func
mypy.modulefinder.highest_init_level(fscache:FileSystemCache, id:str, path:str, prefix:str) -> intCompute the highest level where an __init__ file is found.
func
mypy.modulefinder.verify_module(fscache:FileSystemCache, id:str, path:str, prefix:str) -> boolCheck that all packages containing id have a __init__ file.
class
mypy.moduleinspect.ModuleInspectPerform runtime introspection of modules in a separate process.
method
mypy.moduleinspect.ModuleInspect.close() -> NoneFree any resources used.
func
mypy.moduleinspect.get_package_properties(package_id:str) -> ModulePropertiesUse runtime introspection to get information about a module/package.
func
mypy.moduleinspect.worker(tasks:Queue[str], results:Queue[str | ModuleProperties], sys_path:list[str]) -> NoneThe main loop of a worker introspection process.
class
mypy.mro.MroErrorRaised if a consistent mro cannot be determined for a class.
func
mypy.mro.calculate_mro(info:TypeInfo, obj_type:Callable[[], Instance] | None=None) -> NoneCalculate and set mro (method resolution order).
method
mypy.nativeparse.State.add_error(message:str, line:int, column:int, *blocker:bool=False, *code:str) -> NoneReport an error at a specific location.
func
mypy.nativeparse.deserialize_imports(import_bytes:bytes) -> list[ImportBase]Deserialize import metadata from bytes into mypy AST nodes.
func
mypy.nativeparse.get_executable_if_block_with_overloads(stmt:IfStmt, options:Options) -> tuple[Block | None, IfStmt | None]Return block from IfStmt that will get executed.
func
mypy.nativeparse.is_stripped_if_stmt(stmt:Statement) -> boolCheck stmt to make sure it is a stripped IfStmt.
func
mypy.nativeparse.read_call_type(state:State, data:ReadBuffer) -> TypeRead Call in type context (Arg/DefaultArg/VarArg/KwArg constructor).
func
mypy.nativeparse.read_parameters(state:State, data:ReadBuffer) -> tuple[list[Argument], bool]Read function/lambda parameters.
func
mypy.nativeparse.read_type_alias_stmt(state:State, data:ReadBuffer) -> TypeAliasStmtRead PEP 695 type alias statement.
func
mypy.nativeparse.read_type_params(state:State, data:ReadBuffer) -> list[TypeParam]Read type parameters (PEP 695 generics).
func
mypy.nativeparse.strip_contents_from_if_stmt(stmt:IfStmt) -> NoneRemove contents from IfStmt.
class
mypy.nodes.ArgumentA single argument in a FuncItem.
class
mypy.nodes.AssertTypeExprRepresents a typing.assert_type(expr, type) call.
class
mypy.nodes.AssignmentExprAssignment expressions in Python 3.8+, like "a := 2".
class
mypy.nodes.AssignmentStmtAssignment statement.
class
mypy.nodes.AwaitExprAwait expression (await ...).
class
mypy.nodes.BytesExprBytes literal
class
mypy.nodes.CallExprCall expression.
class
mypy.nodes.CastExprCast expression cast(type, expr).
class
mypy.nodes.ClassDefClass definition
class
mypy.nodes.ComparisonExprComparison expression (e.g.
class
mypy.nodes.ComplexExprComplex literal
class
mypy.nodes.ConditionalExprConditional expression (e.g.
class
mypy.nodes.ContextBase type for objects that are valid as error message locations.
class
mypy.nodes.DataclassTransformSpecSpecifies how a dataclass-like transform should be applied.
class
mypy.nodes.DecoratorA decorated function.
class
mypy.nodes.DictExprDictionary literal expression {key: value, ...}.
class
mypy.nodes.DictionaryComprehensionDictionary comprehension (e.g.
class
mypy.nodes.EllipsisExprEllipsis (...)
class
mypy.nodes.EnumCallExprNamed tuple expression Enum('name', 'val1 val2 ...').
class
mypy.nodes.ExpressionAn expression node.
class
mypy.nodes.ExpressionStmtAn expression as a statement, such as print(s).
class
mypy.nodes.FakeExpressionA dummy expression.
class
mypy.nodes.FileRawDataRaw (binary) data representing parsed, but not deserialized file.
class
mypy.nodes.FloatExprFloat literal
class
mypy.nodes.FuncBaseAbstract base class for function-like nodes.
class
mypy.nodes.FuncDefFunction definition.
class
mypy.nodes.FuncItemBase class for nodes usable as overloaded function items.
class
mypy.nodes.GeneratorExprGenerator expression ...
class
mypy.nodes.GlobalDeclDeclaration global x, y, ...
class
mypy.nodes.Importimport m [as n]
class
mypy.nodes.ImportAllfrom m import *
class
mypy.nodes.ImportBaseBase class for all import statements.
class
mypy.nodes.ImportFromfrom m import x [as y], ...
class
mypy.nodes.IndexExprIndex expression x[y].
class
mypy.nodes.IntExprInteger literal
class
mypy.nodes.LambdaExprLambda expression
method
mypy.nodes.LambdaExpr.expr() -> ExpressionReturn the expression (the body) of the lambda.
class
mypy.nodes.ListComprehensionList comprehension (e.g.
class
mypy.nodes.ListExprList literal expression [...].
class
mypy.nodes.MemberExprMember access expression x.y
class
mypy.nodes.MypyFileThe abstract syntax tree of a single source file.
method
mypy.nodes.MypyFile.local_definitions(*impl_only:bool=False) -> Iterator[Definition]Return all definitions within the module (including nested).
About this data
These signatures were extracted from the public source of python/mypy
using Python's ast module. Argument names, default values,
type annotations and return types are taken verbatim from the code.
Implementation bodies are never stored. See
how it works for details.