class documentation

Mypy type checker. Type check mypy source files that have been semantically analyzed. You must create a separate instance for each source file.

Method __init__ Construct a type checker.
Method accept Type check a node in the given type context.
Method accept_loop Repeatedly type check a loop body until the frame doesn't change. If exit_condition is set, assume it must be False on exit from the loop.
Method add_any_attribute_to_type Inject an extra attribute with Any type using fallbacks.
Method analyze_async_iterable_item_type Analyse async iterable expression and return iterator and iterator item types.
Method analyze_container_item_type Check if a type is a nominal container of a union of such.
Method analyze_index_variables Type check or infer for loop or list comprehension index vars.
Method analyze_iterable_item_type Analyse iterable expression and return iterator and iterator item types.
Method analyze_iterable_item_type_without_expression Analyse iterable type and return iterator and iterator item types.
Method analyze_range_native_int_type Try to infer native int item type from arguments to range(...).
Method bind_and_map_method Bind self-type and map type variables for a method.
Method check___new___signature Undocumented
Method check__exit__return_type Generate error if the return type of __exit__ is problematic.
Method check_assignment Type check a single assignment: lvalue = rvalue.
Method check_assignment_to_multiple_lvalues Undocumented
Method check_assignment_to_slots Undocumented
Method check_async_with_item Undocumented
Method check_compatibility Check if attribute name in base1 is compatible with base2 in multiple inheritance.
Method check_compatibility_all_supers Undocumented
Method check_compatibility_classvar_super Undocumented
Method check_compatibility_final_super Check if an assignment overrides a final attribute in a base class.
Method check_compatibility_super Undocumented
Method check_default_args Undocumented
Method check_enum Undocumented
Method check_enum_bases Non-enum mixins cannot appear after enum bases; this is disallowed at runtime:
Method check_enum_new Undocumented
Method check_except_handler_test Type check an exception handler test clause.
Method check_final Check if this assignment does not assign to a final attribute.
Method check_final_deletable Undocumented
Method check_final_enum Undocumented
Method check_first_pass Type check the entire file, but defer functions with unresolved references.
Method check_for_missing_annotations Undocumented
Method check_for_untyped_decorator Undocumented
Method check_func_def Type check a function definition.
Method check_func_item Type check a function.
Method check_getattr_method Undocumented
Method check_if_final_var_override_writable Check that a final variable doesn't override writeable attribute.
Method check_import Undocumented
Method check_incompatible_property_override Undocumented
Method check_indexed_assignment Type check indexed assignment base[index] = rvalue.
Method check_init_subclass Check that keywords in a class definition are valid arguments for __init_subclass__().
Method check_inplace_operator_method Check an inplace operator method such as __iadd__.
Method check_lvalue Undocumented
Method check_match_args Check that __match_args__ contains literal strings
Method check_member_assignment Type member assignment.
Method check_metaclass_compatibility Ensures that metaclasses of all parent types are compatible.
Method check_method_or_accessor_override_for_base Check if method definition is compatible with a base class.
Method check_method_override Check if function definition is compatible with base classes.
Method check_method_override_for_base_with_name Check if overriding an attribute `name` of `base` with `defn` is valid.
Method check_multi_assignment Check the assignment of one rvalue to a number of lvalues.
Method check_multi_assignment_from_iterable Undocumented
Method check_multi_assignment_from_tuple Undocumented
Method check_multi_assignment_from_union Check assignment to multiple lvalue targets when rvalue type is a Union[...]. For example:
Method check_multiple_inheritance Check for multiple inheritance related errors.
Method check_overlapping_op_methods Check for overlapping method and reverse method signatures.
Method check_overlapping_overloads Undocumented
Method check_override Check a method override with given signatures.
Method check_partial Undocumented
Method check_possible_missing_await Check if the given type becomes a subtype when awaited.
Method check_protocol_variance Check that protocol definition is compatible with declared variances of type variables.
Method check_return_stmt Undocumented
Method check_reverse_op_method Check a reverse operator method such as __radd__.
Method check_rvalue_count_in_assignment Undocumented
Method check_second_pass Run second or following pass of type checking.
Method check_setattr_method Undocumented
Method check_simple_assignment Undocumented
Method check_slots_definition Check the type of __slots__.
Method check_subtype Generate an error if the subtype is not compatible with supertype.
Method check_top_level Check only the top-level of a module, skipping function definitions.
Method check_type_alias_rvalue Undocumented
Method check_unbound_return_typevar Fails when the return typevar is not defined in arguments.
Method check_untyped_after_decorator Undocumented
Method check_with_item Undocumented
Method checking_await_set Undocumented
Method conditional_callable_type_map Takes in an expression and the current type of the expression.
Method conditional_types_for_iterable Narrows the type of `iterable_type` based on the type of `item_type`. For now, we only support narrowing unions of TypedDicts based on left operand being literal string(s).
Method conditional_types_with_intersection Undocumented
Method contains_none Undocumented
Method default_exception_type Exception type to return in case of a previous type error.
Method defer_node Defer a node for processing during next type-checking pass.
Method determine_type_of_member Undocumented
Method enter_attribute_inference_context Undocumented
Method enter_final_context Store whether the current checked assignment is a final declaration.
Method enter_partial_types Enter a new scope for collecting partial types.
Method expand_typevars Undocumented
Method fail Produce an error message.
Method find_isinstance_check Find any isinstance checks (within a chain of ands). Includes implicit and explicit checks for None and calls to callable. Also includes TypeGuard functions.
Method find_isinstance_check_helper Undocumented
Method find_partial_types Look for an active partial type scope containing variable.
Method find_partial_types_in_all_scopes Look for partial type scope containing variable.
Method find_type_equals_check Narrow types based on any checks of the type ``type(x) == T``
Method flatten_lvalues Undocumented
Method function_type Undocumented
Method get_coroutine_return_type Undocumented
Method get_final_context Check whether we a currently checking a final declaration.
Method get_generator_receive_type Given a declared generator return type (t), return the type its yield receives (tc).
Method get_generator_return_type Given the declared return type of a generator (t), return the type it returns (tr).
Method get_generator_yield_type Given the declared return type of a generator (t), return the type it yields (ty).
Method get_isinstance_type Undocumented
Method get_op_other_domain Undocumented
Method get_precise_awaitable_type If type implements Awaitable[X] with non-Any X, return X.
Method get_types_from_except_handler Helper for check_except_handler_test to retrieve handler types.
Method get_variable_type_context Undocumented
Method handle_cannot_determine_type Undocumented
Method handle_partial_var_type Handle a reference to a partial type through a var.
Method has_type Undocumented
Method has_valid_attribute Undocumented
Method hasattr_type_maps Simple support for hasattr() checks.
Method in_checked_function Should we type-check the current function?
Method infer_issubclass_maps Infer type restrictions for an expression in issubclass call.
Method infer_partial_type Undocumented
Method infer_variable_type Infer the type of initialized variables from initializer type.
Method infer_variable_types_from_type_maps Undocumented
Method inference_error_fallback_type Undocumented
Method intersect_instance_callable Creates a fake type that represents the intersection of an Instance and a CallableType.
Method intersect_instances Try creating an ad-hoc intersection of the given instances.
Method is_assignable_slot Undocumented
Method is_async_generator_return_type Is `typ` a valid type for an async generator?
Method is_defined_in_base_class Undocumented
Method is_definition Undocumented
Method is_final_enum_value Undocumented
Method is_forward_op_method Undocumented
Method is_generator_return_type Is `typ` a valid type for a generator/coroutine?
Method is_literal_enum Returns true if this expression (with the given type context) is an Enum literal.
Method is_raising_or_empty Returns 'true' if the given statement either throws an error of some kind or is a no-op.
Method is_reverse_op_method Undocumented
Method is_unsafe_overlapping_op Undocumented
Method is_valid_defaultdict_partial_value_type Check if t can be used as the basis for a partial defaultdict value type.
Method is_writable_attribute Check if an attribute is writable
Method iterable_item_type Undocumented
Method local_type_map Store inferred types into a temporary type map (returned).
Method lookup Look up a definition from the symbol table with the given name.
Method lookup_qualified Undocumented
Method lookup_type Undocumented
Method lookup_type_or_none Undocumented
Method lookup_typeinfo Undocumented
Method lvalue_type_for_inference Undocumented
Method lvalue_type_from_base For a NameExpr that is part of a class, walk all base classes and try to find the first class that defines a Type for the same name.
Method make_fake_callable Produce a new type that makes type Callable with a generic callable type.
Method make_fake_typeinfo Undocumented
Method named_generic_type Return an instance with the given name and type arguments.
Method named_type Return an instance type with given name and implicit Any type args.
Method note Produce a note.
Method partition_by_callable Partitions a type into callable subtypes and uncallable subtypes.
Method partition_union_by_attr Undocumented
Method propagate_up_typemap_info Attempts refining parent expressions of any MemberExpr or IndexExprs in new_types.
Method push_type_map Undocumented
Method refine_away_none_in_comparison Produces conditional type maps refining away None in an identity/equality chain.
Method refine_identity_comparison_expression Produce conditional type maps refining expressions by an identity/equality comparison.
Method refine_parent_types Checks if the given expr is a 'lookup operation' into a union and iteratively refines the parent types based on the 'expr_type'.
Method remove_capture_conflicts Undocumented
Method reset Cleanup stale state that might be left over from a typechecking run.
Method set_inference_error_fallback_type Store best known type for variable if type inference failed.
Method set_inferred_type Store inferred variable type.
Method should_report_unreachable_issues Undocumented
Method simple_rvalue Returns True for expressions for which inferred type should not depend on context.
Method split_around_star Splits a list of items in three to match another list of length 'length' that contains a starred expression at 'star_index' in the following way:
Method store_type Store the type of a node in the type map.
Method store_types Undocumented
Method str_type Return instance type 'str'.
Method temp_node Create a temporary node with the given, fixed type.
Method try_infer_partial_generic_type_from_assignment Try to infer a precise type for partial generic type from assignment.
Method try_infer_partial_type_from_indexed_assignment Undocumented
Method type_check_raise Undocumented
Method type_is_iterable Undocumented
Method type_requires_usage Some types require usage in all cases. The classic example is an unused coroutine.
Method type_type Return instance type 'type'.
Method visit_assert_stmt Undocumented
Method visit_assignment_stmt Type check an assignment statement.
Method visit_block Undocumented
Method visit_break_stmt Undocumented
Method visit_class_def Type check a class definition.
Method visit_continue_stmt Undocumented
Method visit_decorator Undocumented
Method visit_del_stmt Undocumented
Method visit_expression_stmt Undocumented
Method visit_for_stmt Type check a for statement.
Method visit_func_def Undocumented
Method visit_if_stmt Type check an if statement.
Method visit_import Undocumented
Method visit_import_all Undocumented
Method visit_import_from Undocumented
Method visit_match_stmt Undocumented
Method visit_operator_assignment_stmt Type check an operator assignment statement, e.g. x += 1.
Method visit_overloaded_func_def Undocumented
Method visit_raise_stmt Type check a raise statement.
Method visit_return_stmt Type check a return statement.
Method visit_try_stmt Type check a try statement.
Method visit_try_without_finally Type check a try statement, ignoring the finally block.
Method visit_while_stmt Type check a while statement.
Method visit_with_stmt Undocumented
Method wrap_exception_group Transform except* variable type into an appropriate exception group.
Constant partial_type_augmented_ops Undocumented
Instance Variable allow_abstract_call Undocumented
Instance Variable binder Undocumented
Instance Variable checking_missing_await Undocumented
Instance Variable current_node_deferred Undocumented
Instance Variable deferred_nodes Undocumented
Instance Variable dynamic_funcs Undocumented
Instance Variable errors Undocumented
Instance Variable expr_checker Undocumented
Instance Variable globals Undocumented
Instance Variable inferred_attribute_types Undocumented
Instance Variable is_stub Undocumented
Instance Variable is_typeshed_stub Undocumented
Instance Variable module_refs Undocumented
Instance Variable modules Undocumented
Instance Variable msg Undocumented
Instance Variable no_partial_types Undocumented
Instance Variable options Undocumented
Instance Variable partial_reported Undocumented
Instance Variable partial_types Undocumented
Instance Variable pass_num Undocumented
Instance Variable path Undocumented
Instance Variable pattern_checker Undocumented
Instance Variable plugin Undocumented
Instance Variable recurse_into_functions Undocumented
Instance Variable return_types Undocumented
Instance Variable scope Undocumented
Instance Variable temp_type_map Undocumented
Instance Variable tree Undocumented
Instance Variable tscope Undocumented
Instance Variable var_decl_frames Undocumented
Property type_context Return the type context of the plugin
Method _check_for_truthy_type Undocumented
Method _is_truthy_type Undocumented
Method _visit_func_def Type check a function definition.
Method _visit_overloaded_func_def Undocumented
Instance Variable _is_final_def Undocumented
Instance Variable _type_maps Undocumented

Inherited from NodeVisitor:

Method visit__promote_expr Undocumented
Method visit_as_pattern Undocumented
Method visit_assert_type_expr Undocumented
Method visit_assignment_expr Undocumented
Method visit_await_expr Undocumented
Method visit_bytes_expr Undocumented
Method visit_call_expr Undocumented
Method visit_cast_expr Undocumented
Method visit_class_pattern Undocumented
Method visit_comparison_expr Undocumented
Method visit_complex_expr Undocumented
Method visit_conditional_expr Undocumented
Method visit_dict_expr Undocumented
Method visit_dictionary_comprehension Undocumented
Method visit_ellipsis Undocumented
Method visit_enum_call_expr Undocumented
Method visit_float_expr Undocumented
Method visit_generator_expr Undocumented
Method visit_global_decl Undocumented
Method visit_index_expr Undocumented
Method visit_int_expr Undocumented
Method visit_lambda_expr Undocumented
Method visit_list_comprehension Undocumented
Method visit_list_expr Undocumented
Method visit_mapping_pattern Undocumented
Method visit_member_expr Undocumented
Method visit_mypy_file Undocumented
Method visit_name_expr Undocumented
Method visit_namedtuple_expr Undocumented
Method visit_newtype_expr Undocumented
Method visit_nonlocal_decl Undocumented
Method visit_op_expr Undocumented
Method visit_or_pattern Undocumented
Method visit_paramspec_expr Undocumented
Method visit_pass_stmt Undocumented
Method visit_placeholder_node Undocumented
Method visit_reveal_expr Undocumented
Method visit_sequence_pattern Undocumented
Method visit_set_comprehension Undocumented
Method visit_set_expr Undocumented
Method visit_singleton_pattern Undocumented
Method visit_slice_expr Undocumented
Method visit_star_expr Undocumented
Method visit_starred_pattern Undocumented
Method visit_str_expr Undocumented
Method visit_super_expr Undocumented
Method visit_temp_node Undocumented
Method visit_tuple_expr Undocumented
Method visit_type_alias Undocumented
Method visit_type_alias_expr Undocumented
Method visit_type_application Undocumented
Method visit_type_var_expr Undocumented
Method visit_type_var_tuple_expr Undocumented
Method visit_typeddict_expr Undocumented
Method visit_unary_expr Undocumented
Method visit_value_pattern Undocumented
Method visit_var Undocumented
Method visit_yield_expr Undocumented
Method visit_yield_from_expr Undocumented
def __init__(self, errors: Errors, modules: dict[str, MypyFile], options: Options, tree: MypyFile, path: str, plugin: Plugin, per_line_checking_time_ns: dict[int, int]): (source)

Construct a type checker. Use errors to report type check errors.

def accept(self, stmt: Statement): (source)

Type check a node in the given type context.

def accept_loop(self, body: Statement, else_body: Statement|None = None, *, exit_condition: Expression|None = None): (source)

Repeatedly type check a loop body until the frame doesn't change. If exit_condition is set, assume it must be False on exit from the loop. Then check the else_body.

def add_any_attribute_to_type(self, typ: Type, name: str) -> Type: (source)

Inject an extra attribute with Any type using fallbacks.

def analyze_async_iterable_item_type(self, expr: Expression) -> tuple[Type, Type]: (source)

Analyse async iterable expression and return iterator and iterator item types.

def analyze_container_item_type(self, typ: Type) -> Type|None: (source)

Check if a type is a nominal container of a union of such. Return the corresponding container item type.

def analyze_index_variables(self, index: Expression, item_type: Type, infer_lvalue_type: bool, context: Context): (source)

Type check or infer for loop or list comprehension index vars.

def analyze_iterable_item_type(self, expr: Expression) -> tuple[Type, Type]: (source)

Analyse iterable expression and return iterator and iterator item types.

def analyze_iterable_item_type_without_expression(self, type: Type, context: Context) -> tuple[Type, Type]: (source)

Analyse iterable type and return iterator and iterator item types.

def analyze_range_native_int_type(self, expr: Expression) -> Type|None: (source)

Try to infer native int item type from arguments to range(...). For example, return i64 if the expression is "range(0, i64(n))". Return None if unsuccessful.

def bind_and_map_method(self, sym: SymbolTableNode, typ: FunctionLike, sub_info: TypeInfo, super_info: TypeInfo) -> FunctionLike: (source)

Bind self-type and map type variables for a method. Arguments: sym: a symbol that points to method definition typ: method type on the definition sub_info: class where the method is used super_info: class where the method was defined

def check___new___signature(self, fdef: FuncDef, typ: CallableType): (source)

Undocumented

def check__exit__return_type(self, defn: FuncItem): (source)

Generate error if the return type of __exit__ is problematic. If __exit__ always returns False but the return type is declared as bool, mypy thinks that a with statement may "swallow" exceptions even though this is not the case, resulting in invalid reachability inference.

def check_assignment(self, lvalue: Lvalue, rvalue: Expression, infer_lvalue_type: bool = True, new_syntax: bool = False): (source)

Type check a single assignment: lvalue = rvalue.

def check_assignment_to_multiple_lvalues(self, lvalues: list[Lvalue], rvalue: Expression, context: Context, infer_lvalue_type: bool = True): (source)

Undocumented

def check_assignment_to_slots(self, lvalue: Lvalue): (source)

Undocumented

def check_async_with_item(self, expr: Expression, target: Expression|None, infer_lvalue_type: bool) -> Type: (source)

Undocumented

def check_compatibility(self, name: str, base1: TypeInfo, base2: TypeInfo, ctx: TypeInfo): (source)

Check if attribute name in base1 is compatible with base2 in multiple inheritance. Assume base1 comes before base2 in the MRO, and that base1 and base2 don't have a direct subclass relationship (i.e., the compatibility requirement only derives from multiple inheritance). This check verifies that a definition taken from base1 (and mapped to the current class ctx), is type compatible with the definition taken from base2 (also mapped), so that unsafe subclassing like this can be detected: class A(Generic[T]): def foo(self, x: T) -> None: ... class B: def foo(self, x: str) -> None: ... class C(B, A[int]): ... # this is unsafe because... x: A[int] = C() x.foo # ...runtime type is (str) -> None, while static type is (int) -> None

def check_compatibility_all_supers(self, lvalue: RefExpr, lvalue_type: Type|None, rvalue: Expression) -> bool: (source)

Undocumented

def check_compatibility_classvar_super(self, node: Var, base: TypeInfo, base_node: Node|None) -> bool: (source)

Undocumented

def check_compatibility_final_super(self, node: Var, base: TypeInfo, base_node: Node|None) -> bool: (source)

Check if an assignment overrides a final attribute in a base class. This only checks situations where either a node in base class is not a variable but a final method, or where override is explicitly declared as final. In these cases we give a more detailed error message. In addition, we check that a final variable doesn't override writeable attribute, which is not safe. Other situations are checked in `check_final()`.

def check_compatibility_super(self, lvalue: RefExpr, lvalue_type: Type|None, rvalue: Expression, base: TypeInfo, base_type: Type, base_node: Node) -> bool: (source)

Undocumented

def check_default_args(self, item: FuncItem, body_is_trivial: bool): (source)

Undocumented

def check_enum(self, defn: ClassDef): (source)

Undocumented

def check_enum_bases(self, defn: ClassDef): (source)

Non-enum mixins cannot appear after enum bases; this is disallowed at runtime: class Foo: ... class Bar(enum.Enum, Foo): ... But any number of enum mixins can appear in a class definition (even if multiple enum bases define __new__). So this is fine: class Foo(enum.Enum): def __new__(cls, val): ... class Bar(enum.Enum): def __new__(cls, val): ... class Baz(int, Foo, Bar, enum.Flag): ...

def check_enum_new(self, defn: ClassDef): (source)

Undocumented

def check_except_handler_test(self, n: Expression, is_star: bool) -> Type: (source)

Type check an exception handler test clause.

Check if this assignment does not assign to a final attribute. This function performs the check only for name assignments at module and class scope. The assignments to `obj.attr` and `Cls.attr` are checked in checkmember.py.

def check_final_deletable(self, typ: TypeInfo): (source)

Undocumented

def check_final_enum(self, defn: ClassDef, base: TypeInfo): (source)

Undocumented

def check_first_pass(self): (source)

Type check the entire file, but defer functions with unresolved references. Unresolved references are forward references to variables whose types haven't been inferred yet. They may occur later in the same file or in a different file that's being processed later (usually due to an import cycle). Deferred functions will be processed by check_second_pass().

def check_for_missing_annotations(self, fdef: FuncItem): (source)

Undocumented

def check_for_untyped_decorator(self, func: FuncDef, dec_type: Type, dec_expr: Expression): (source)

Undocumented

def check_func_def(self, defn: FuncItem, typ: CallableType, name: str|None, allow_empty: bool = False): (source)

Type check a function definition.

def check_func_item(self, defn: FuncItem, type_override: CallableType|None = None, name: str|None = None, allow_empty: bool = False): (source)

Type check a function. If type_override is provided, use it as the function type.

def check_getattr_method(self, typ: Type, context: Context, name: str): (source)

Undocumented

def check_if_final_var_override_writable(self, name: str, base_node: Node|None, ctx: Context): (source)

Check that a final variable doesn't override writeable attribute. This is done to prevent situations like this: class C: attr = 1 class D(C): attr: Final = 2 x: C = D() x.attr = 3 # Oops!

def check_import(self, node: ImportBase): (source)

Undocumented

def check_incompatible_property_override(self, e: Decorator): (source)

Undocumented

def check_indexed_assignment(self, lvalue: IndexExpr, rvalue: Expression, context: Context): (source)

Type check indexed assignment base[index] = rvalue. The lvalue argument is the base[index] expression.

def check_init_subclass(self, defn: ClassDef): (source)

Check that keywords in a class definition are valid arguments for __init_subclass__(). In this example: 1 class Base: 2 def __init_subclass__(cls, thing: int): 3 pass 4 class Child(Base, thing=5): 5 def __init_subclass__(cls): 6 pass 7 Child() Base.__init_subclass__(thing=5) is called at line 4. This is what we simulate here. Child.__init_subclass__ is never called.

def check_inplace_operator_method(self, defn: FuncBase): (source)

Check an inplace operator method such as __iadd__. They cannot arbitrarily overlap with __add__.

def check_lvalue(self, lvalue: Lvalue) -> tuple[Type|None, IndexExpr|None, Var|None]: (source)

Undocumented

def check_match_args(self, var: Var, typ: Type, context: Context): (source)

Check that __match_args__ contains literal strings

def check_member_assignment(self, instance_type: Type, attribute_type: Type, rvalue: Expression, context: Context) -> tuple[Type, Type, bool]: (source)

Type member assignment. This defers to check_simple_assignment, unless the member expression is a descriptor, in which case this checks descriptor semantics as well. Return the inferred rvalue_type, inferred lvalue_type, and whether to use the binder for this assignment. Note: this method exists here and not in checkmember.py, because we need to take care about interaction between binder and __set__().

def check_metaclass_compatibility(self, typ: TypeInfo): (source)

Ensures that metaclasses of all parent types are compatible.

def check_method_or_accessor_override_for_base(self, defn: (FuncDef|OverloadedFuncDef)|Decorator, base: TypeInfo) -> bool: (source)

Check if method definition is compatible with a base class. Return True if the node was deferred because one of the corresponding superclass nodes is not ready.

def check_method_override(self, defn: (FuncDef|OverloadedFuncDef)|Decorator): (source)

Check if function definition is compatible with base classes. This may defer the method if a signature is not available in at least one base class.

def check_method_override_for_base_with_name(self, defn: (FuncDef|OverloadedFuncDef)|Decorator, name: str, base: TypeInfo) -> bool: (source)

Check if overriding an attribute `name` of `base` with `defn` is valid. Return True if the supertype node was not analysed yet, and `defn` was deferred.

def check_multi_assignment(self, lvalues: list[Lvalue], rvalue: Expression, context: Context, infer_lvalue_type: bool = True, rv_type: Type|None = None, undefined_rvalue: bool = False): (source)

Check the assignment of one rvalue to a number of lvalues.

def check_multi_assignment_from_iterable(self, lvalues: list[Lvalue], rvalue_type: Type, context: Context, infer_lvalue_type: bool = True): (source)

Undocumented

def check_multi_assignment_from_tuple(self, lvalues: list[Lvalue], rvalue: Expression, rvalue_type: TupleType, context: Context, undefined_rvalue: bool, infer_lvalue_type: bool = True): (source)

Undocumented

def check_multi_assignment_from_union(self, lvalues: list[Expression], rvalue: Expression, rvalue_type: UnionType, context: Context, infer_lvalue_type: bool): (source)

Check assignment to multiple lvalue targets when rvalue type is a Union[...]. For example: t: Union[Tuple[int, int], Tuple[str, str]] x, y = t reveal_type(x) # Union[int, str] The idea in this case is to process the assignment for every item of the union. Important note: the types are collected in two places, 'union_types' contains inferred types for first assignments, 'assignments' contains the narrowed types for binder.

def check_multiple_inheritance(self, typ: TypeInfo): (source)

Check for multiple inheritance related errors.

def check_overlapping_op_methods(self, reverse_type: CallableType, reverse_name: str, reverse_class: TypeInfo, forward_type: Type, forward_name: str, forward_base: Type, context: Context): (source)

Check for overlapping method and reverse method signatures. This function assumes that: - The reverse method has valid argument count and kinds. - If the reverse operator method accepts some argument of type X, the forward operator method also belong to class X. For example, if we have the reverse operator `A.__radd__(B)`, then the corresponding forward operator must have the type `B.__add__(...)`.

def check_overlapping_overloads(self, defn: OverloadedFuncDef): (source)

Undocumented

def check_override(self, override: FunctionLike, original: FunctionLike, name: str, name_in_super: str, supertype: str, original_class_or_static: bool, override_class_or_static: bool, node: Context): (source)

Check a method override with given signatures. Arguments: override: The signature of the overriding method. original: The signature of the original supertype method. name: The name of the subtype. This and the next argument are only used for generating error messages. supertype: The name of the supertype.

Undocumented

def check_possible_missing_await(self, subtype: Type, supertype: Type, context: Context): (source)

Check if the given type becomes a subtype when awaited.

def check_protocol_variance(self, defn: ClassDef): (source)

Check that protocol definition is compatible with declared variances of type variables. Note that we also prohibit declaring protocol classes as invariant if they are actually covariant/contravariant, since this may break transitivity of subtyping, see PEP 544.

def check_return_stmt(self, s: ReturnStmt): (source)

Undocumented

def check_reverse_op_method(self, defn: FuncItem, reverse_type: CallableType, reverse_name: str, context: Context): (source)

Check a reverse operator method such as __radd__.

def check_rvalue_count_in_assignment(self, lvalues: list[Lvalue], rvalue_count: int, context: Context) -> bool: (source)

Undocumented

def check_second_pass(self, todo: Sequence[DeferredNode|FineGrainedDeferredNode]|None = None) -> bool: (source)

Run second or following pass of type checking. This goes through deferred nodes, returning True if there were any.

def check_setattr_method(self, typ: Type, context: Context): (source)

Undocumented

def check_simple_assignment(self, lvalue_type: Type|None, rvalue: Expression, context: Context, msg: ErrorMessage = message_registry.INCOMPATIBLE_TYPES_IN_ASSIGNMENT, lvalue_name: str = 'variable', rvalue_name: str = 'expression', *, notes: list[str]|None = None) -> Type: (source)

Undocumented

def check_slots_definition(self, typ: Type, context: Context): (source)

Check the type of __slots__.

@overload
def check_subtype(self, subtype: Type, supertype: Type, context: Context, msg: str, subtype_label: str|None = None, supertype_label: str|None = None, *, notes: list[str]|None = None, code: ErrorCode|None = None, outer_context: Context|None = None) -> bool:
@overload
def check_subtype(self, subtype: Type, supertype: Type, context: Context, msg: ErrorMessage, subtype_label: str|None = None, supertype_label: str|None = None, *, notes: list[str]|None = None, outer_context: Context|None = None) -> bool:
(source)

Generate an error if the subtype is not compatible with supertype.

def check_top_level(self, node: MypyFile): (source)

Check only the top-level of a module, skipping function definitions.

def check_type_alias_rvalue(self, s: AssignmentStmt): (source)

Undocumented

def check_unbound_return_typevar(self, typ: CallableType): (source)

Fails when the return typevar is not defined in arguments.

def check_untyped_after_decorator(self, typ: Type, func: FuncDef): (source)

Undocumented

def check_with_item(self, expr: Expression, target: Expression|None, infer_lvalue_type: bool) -> Type: (source)

Undocumented

@contextmanager
def checking_await_set(self) -> Iterator[None]: (source)

Undocumented

def conditional_callable_type_map(self, expr: Expression, current_type: Type|None) -> tuple[TypeMap, TypeMap]: (source)

Takes in an expression and the current type of the expression. Returns a 2-tuple: The first element is a map from the expression to the restricted type if it were callable. The second element is a map from the expression to the type it would hold if it weren't callable.

def conditional_types_for_iterable(self, item_type: Type, iterable_type: Type) -> tuple[Type|None, Type|None]: (source)

Narrows the type of `iterable_type` based on the type of `item_type`. For now, we only support narrowing unions of TypedDicts based on left operand being literal string(s).

@overload
def conditional_types_with_intersection(self, expr_type: Type, type_ranges: list[TypeRange]|None, ctx: Context, default: None = None) -> tuple[Type|None, Type|None]:
@overload
def conditional_types_with_intersection(self, expr_type: Type, type_ranges: list[TypeRange]|None, ctx: Context, default: Type) -> tuple[Type, Type]:
(source)

Undocumented

def contains_none(self, t: Type) -> bool: (source)

Undocumented

def default_exception_type(self, is_star: bool) -> Type: (source)

Exception type to return in case of a previous type error.

def defer_node(self, node: DeferredNodeType, enclosing_class: TypeInfo|None): (source)

Defer a node for processing during next type-checking pass. Args: node: function/method being deferred enclosing_class: for methods, the class where the method is defined NOTE: this can't handle nested functions/methods.

def determine_type_of_member(self, sym: SymbolTableNode) -> Type|None: (source)

Undocumented

@contextmanager
def enter_attribute_inference_context(self) -> Iterator[None]: (source)

Undocumented

@contextmanager
def enter_final_context(self, is_final_def: bool) -> Iterator[None]: (source)

Store whether the current checked assignment is a final declaration.

@contextmanager
def enter_partial_types(self, *, is_function: bool = False, is_class: bool = False) -> Iterator[None]: (source)

Enter a new scope for collecting partial types. Also report errors for (some) variables which still have partial types, i.e. we couldn't infer a complete type.

def expand_typevars(self, defn: FuncItem, typ: CallableType) -> list[tuple[FuncItem, CallableType]]: (source)

Undocumented

def fail(self, msg: str|ErrorMessage, context: Context, *, code: ErrorCode|None = None): (source)

Produce an error message.

def find_isinstance_check(self, node: Expression) -> tuple[TypeMap, TypeMap]: (source)

Find any isinstance checks (within a chain of ands). Includes implicit and explicit checks for None and calls to callable. Also includes TypeGuard functions. Return value is a map of variables to their types if the condition is true and a map of variables to their types if the condition is false. If either of the values in the tuple is None, then that particular branch can never occur. May return {}, {}. Can return None, None in situations involving NoReturn.

def find_isinstance_check_helper(self, node: Expression) -> tuple[TypeMap, TypeMap]: (source)

Undocumented

def find_partial_types(self, var: Var) -> dict[Var, Context]|None: (source)

Look for an active partial type scope containing variable. A scope is active if assignments in the current context can refine a partial type originally defined in the scope. This is affected by the local_partial_types configuration option.

def find_partial_types_in_all_scopes(self, var: Var) -> tuple[bool, bool, dict[Var, Context]|None]: (source)

Look for partial type scope containing variable. Return tuple (is the scope active, is the scope a local scope, scope).

def find_type_equals_check(self, node: ComparisonExpr, expr_indices: list[int]) -> tuple[TypeMap, TypeMap]: (source)

Narrow types based on any checks of the type ``type(x) == T`` Args: node: The node that might contain the comparison expr_indices: The list of indices of expressions in ``node`` that are being compared

def flatten_lvalues(self, lvalues: list[Expression]) -> list[Expression]: (source)

Undocumented

def function_type(self, func: FuncBase) -> FunctionLike: (source)

Undocumented

def get_coroutine_return_type(self, return_type: Type) -> Type: (source)

Undocumented

def get_final_context(self) -> bool: (source)

Check whether we a currently checking a final declaration.

def get_generator_receive_type(self, return_type: Type, is_coroutine: bool) -> Type: (source)

Given a declared generator return type (t), return the type its yield receives (tc).

def get_generator_return_type(self, return_type: Type, is_coroutine: bool) -> Type: (source)

Given the declared return type of a generator (t), return the type it returns (tr).

def get_generator_yield_type(self, return_type: Type, is_coroutine: bool) -> Type: (source)

Given the declared return type of a generator (t), return the type it yields (ty).

def get_isinstance_type(self, expr: Expression) -> list[TypeRange]|None: (source)

Undocumented

def get_op_other_domain(self, tp: FunctionLike) -> Type|None: (source)

Undocumented

def get_precise_awaitable_type(self, typ: Type, local_errors: ErrorWatcher) -> Type|None: (source)

If type implements Awaitable[X] with non-Any X, return X. In all other cases return None. This method must be called in context of local_errors.

def get_types_from_except_handler(self, typ: Type, n: Expression) -> list[Type]: (source)

Helper for check_except_handler_test to retrieve handler types.

def get_variable_type_context(self, inferred: Var) -> Type|None: (source)

Undocumented

def handle_cannot_determine_type(self, name: str, context: Context): (source)

Undocumented

def handle_partial_var_type(self, typ: PartialType, is_lvalue: bool, node: Var, context: Context) -> Type: (source)

Handle a reference to a partial type through a var. (Used by checkexpr and checkmember.)

def has_type(self, node: Expression) -> bool: (source)

Undocumented

def has_valid_attribute(self, typ: Type, name: str) -> bool: (source)

Undocumented

def hasattr_type_maps(self, expr: Expression, source_type: Type, name: str) -> tuple[TypeMap, TypeMap]: (source)

Simple support for hasattr() checks. Essentially the logic is following: * In the if branch, keep types that already has a valid attribute as is, for other inject an attribute with `Any` type. * In the else branch, remove types that already have a valid attribute, while keeping the rest.

def in_checked_function(self) -> bool: (source)

Should we type-check the current function? - Yes if --check-untyped-defs is set. - Yes outside functions. - Yes in annotated functions. - No otherwise.

def infer_issubclass_maps(self, node: CallExpr, expr: Expression) -> tuple[TypeMap, TypeMap]: (source)

Infer type restrictions for an expression in issubclass call.

def infer_partial_type(self, name: Var, lvalue: Lvalue, init_type: Type) -> bool: (source)

Undocumented

def infer_variable_type(self, name: Var, lvalue: Lvalue, init_type: Type, context: Context): (source)

Infer the type of initialized variables from initializer type.

def infer_variable_types_from_type_maps(self, type_maps: list[TypeMap]) -> dict[Var, Type]: (source)

Undocumented

def inference_error_fallback_type(self, type: Type) -> Type: (source)

Undocumented

def intersect_instance_callable(self, typ: Instance, callable_type: CallableType) -> Instance: (source)

Creates a fake type that represents the intersection of an Instance and a CallableType. It operates by creating a bare-minimum dummy TypeInfo that subclasses type and adds a __call__ method matching callable_type.

def intersect_instances(self, instances: tuple[Instance, Instance], errors: list[tuple[str, str]]) -> Instance|None: (source)

Try creating an ad-hoc intersection of the given instances. Note that this function does *not* try and create a full-fledged intersection type. Instead, it returns an instance of a new ad-hoc subclass of the given instances. This is mainly useful when you need a way of representing some theoretical subclass of the instances the user may be trying to use the generated intersection can serve as a placeholder. This function will create a fresh subclass every time you call it, even if you pass in the exact same arguments. So this means calling `self.intersect_intersection([inst_1, inst_2], ctx)` twice will result in instances of two distinct subclasses of inst_1 and inst_2. This is by design: we want each ad-hoc intersection to be unique since they're supposed represent some other unknown subclass. Returns None if creating the subclass is impossible (e.g. due to MRO errors or incompatible signatures). If we do successfully create a subclass, its TypeInfo will automatically be added to the global scope.

def is_assignable_slot(self, lvalue: Lvalue, typ: Type|None) -> bool: (source)

Undocumented

def is_async_generator_return_type(self, typ: Type) -> bool: (source)

Is `typ` a valid type for an async generator? True if `typ` is a supertype of AsyncGenerator.

def is_defined_in_base_class(self, var: Var) -> bool: (source)

Undocumented

def is_definition(self, s: Lvalue) -> bool: (source)

Undocumented

def is_final_enum_value(self, sym: SymbolTableNode) -> bool: (source)

Undocumented

def is_forward_op_method(self, method_name: str) -> bool: (source)

Undocumented

def is_generator_return_type(self, typ: Type, is_coroutine: bool) -> bool: (source)

Is `typ` a valid type for a generator/coroutine? True if `typ` is a *supertype* of Generator or Awaitable. Also true it it's *exactly* AwaitableGenerator (modulo type parameters).

def is_literal_enum(self, n: Expression) -> bool: (source)

Returns true if this expression (with the given type context) is an Enum literal. For example, if we had an enum: class Foo(Enum): A = 1 B = 2 ...and if the expression 'Foo' referred to that enum within the current type context, then the expression 'Foo.A' would be a literal enum. However, if we did 'a = Foo.A', then the variable 'a' would *not* be a literal enum. We occasionally special-case expressions like 'Foo.A' and treat them as a single primitive unit for the same reasons we sometimes treat 'True', 'False', or 'None' as a single primitive unit.

def is_raising_or_empty(self, s: Statement) -> bool: (source)

Returns 'true' if the given statement either throws an error of some kind or is a no-op. We use this function mostly while handling the '--warn-unreachable' flag. When that flag is present, we normally report an error on any unreachable statement. But if that statement is just something like a 'pass' or a just-in-case 'assert False', reporting an error would be annoying.

def is_reverse_op_method(self, method_name: str) -> bool: (source)

Undocumented

def is_unsafe_overlapping_op(self, forward_item: CallableType, forward_base: Type, reverse_type: CallableType) -> bool: (source)

Undocumented

def is_valid_defaultdict_partial_value_type(self, t: ProperType) -> bool: (source)

Check if t can be used as the basis for a partial defaultdict value type. Examples: * t is 'int' --> True * t is 'list[<nothing>]' --> True * t is 'dict[...]' --> False (only generic types with a single type argument supported)

def is_writable_attribute(self, node: Node) -> bool: (source)

Check if an attribute is writable

def iterable_item_type(self, instance: Instance) -> Type: (source)

Undocumented

@contextmanager
def local_type_map(self) -> Iterator[dict[Expression, Type]]: (source)

Store inferred types into a temporary type map (returned). This can be used to perform type checking "experiments" without affecting exported types (which are used by mypyc).

def lookup(self, name: str) -> SymbolTableNode: (source)

Look up a definition from the symbol table with the given name.

def lookup_qualified(self, name: str) -> SymbolTableNode: (source)

Undocumented

def lookup_type(self, node: Expression) -> Type: (source)

Undocumented

def lookup_type_or_none(self, node: Expression) -> Type|None: (source)

Undocumented

def lookup_typeinfo(self, fullname: str) -> TypeInfo: (source)

Undocumented

def lvalue_type_for_inference(self, lvalues: list[Lvalue], rvalue_type: TupleType) -> Type: (source)

Undocumented

def lvalue_type_from_base(self, expr_node: Var, base: TypeInfo) -> tuple[Type|None, Node|None]: (source)

For a NameExpr that is part of a class, walk all base classes and try to find the first class that defines a Type for the same name.

def make_fake_callable(self, typ: Instance) -> Instance: (source)

Produce a new type that makes type Callable with a generic callable type.

def make_fake_typeinfo(self, curr_module_fullname: str, class_gen_name: str, class_short_name: str, bases: list[Instance]) -> tuple[ClassDef, TypeInfo]: (source)

Undocumented

def named_generic_type(self, name: str, args: list[Type]) -> Instance: (source)

Return an instance with the given name and type arguments. Assume that the number of arguments is correct. Assume that the name refers to a compatible generic type.

def named_type(self, name: str) -> Instance: (source)

Return an instance type with given name and implicit Any type args. For example, named_type('builtins.object') produces the 'object' type.

def note(self, msg: str|ErrorMessage, context: Context, offset: int = 0, *, code: ErrorCode|None = None): (source)

Produce a note.

def partition_by_callable(self, typ: Type, unsound_partition: bool) -> tuple[list[Type], list[Type]]: (source)

Partitions a type into callable subtypes and uncallable subtypes. Thus, given: `callables, uncallables = partition_by_callable(type)` If we assert `callable(type)` then `type` has type Union[*callables], and If we assert `not callable(type)` then `type` has type Union[*uncallables] If unsound_partition is set, assume that anything that is not clearly callable is in fact not callable. Otherwise we generate a new subtype that *is* callable. Guaranteed to not return [], [].

def partition_union_by_attr(self, source_type: UnionType, name: str) -> tuple[list[Type], list[Type]]: (source)

Undocumented

def propagate_up_typemap_info(self, new_types: TypeMap) -> TypeMap: (source)

Attempts refining parent expressions of any MemberExpr or IndexExprs in new_types. Specifically, this function accepts two mappings of expression to original types: the original mapping (existing_types), and a new mapping (new_types) intended to update the original. This function iterates through new_types and attempts to use the information to try refining any parent types that happen to be unions. For example, suppose there are two types "A = Tuple[int, int]" and "B = Tuple[str, str]". Next, suppose that 'new_types' specifies the expression 'foo[0]' has a refined type of 'int' and that 'foo' was previously deduced to be of type Union[A, B]. Then, this function will observe that since A[0] is an int and B[0] is not, the type of 'foo' can be further refined from Union[A, B] into just B. We perform this kind of "parent narrowing" for member lookup expressions and indexing expressions into tuples, namedtuples, and typeddicts. We repeat this narrowing recursively if the parent is also a "lookup expression". So for example, if we have the expression "foo['bar'].baz[0]", we'd potentially end up refining types for the expressions "foo", "foo['bar']", and "foo['bar'].baz". We return the newly refined map. This map is guaranteed to be a superset of 'new_types'.

def push_type_map(self, type_map: TypeMap): (source)

Undocumented

def refine_away_none_in_comparison(self, operands: list[Expression], operand_types: list[Type], chain_indices: list[int], narrowable_operand_indices: AbstractSet[int]) -> tuple[TypeMap, TypeMap]: (source)

Produces conditional type maps refining away None in an identity/equality chain. For more details about what the different arguments mean, see the docstring of 'refine_identity_comparison_expression' up above.

def refine_identity_comparison_expression(self, operands: list[Expression], operand_types: list[Type], chain_indices: list[int], narrowable_operand_indices: AbstractSet[int], is_valid_target: Callable[[ProperType], bool], coerce_only_in_literal_context: bool) -> tuple[TypeMap, TypeMap]: (source)

Produce conditional type maps refining expressions by an identity/equality comparison. The 'operands' and 'operand_types' lists should be the full list of operands used in the overall comparison expression. The 'chain_indices' list is the list of indices actually used within this identity comparison chain. So if we have the expression: a <= b is c is d <= e ...then 'operands' and 'operand_types' would be lists of length 5 and 'chain_indices' would be the list [1, 2, 3]. The 'narrowable_operand_indices' parameter is the set of all indices we are allowed to refine the types of: that is, all operands that will potentially be a part of the output TypeMaps. Although this function could theoretically try setting the types of the operands in the chains to the meet, doing that causes too many issues in real-world code. Instead, we use 'is_valid_target' to identify which of the given chain types we could plausibly use as the refined type for the expressions in the chain. Similarly, 'coerce_only_in_literal_context' controls whether we should try coercing expressions in the chain to a Literal type. Performing this coercion is sometimes too aggressive of a narrowing, depending on context.

def refine_parent_types(self, expr: Expression, expr_type: Type) -> Mapping[Expression, Type]: (source)

Checks if the given expr is a 'lookup operation' into a union and iteratively refines the parent types based on the 'expr_type'. For example, if 'expr' is an expression like 'a.b.c.d', we'll potentially return refined types for expressions 'a', 'a.b', and 'a.b.c'. For more details about what a 'lookup operation' is and how we use the expr_type to refine the parent types of lookup_expr, see the docstring in 'propagate_up_typemap_info'.

def remove_capture_conflicts(self, type_map: TypeMap, inferred_types: dict[Var, Type]): (source)

Undocumented

def reset(self): (source)

Cleanup stale state that might be left over from a typechecking run. This allows us to reuse TypeChecker objects in fine-grained incremental mode.

def set_inference_error_fallback_type(self, var: Var, lvalue: Lvalue, type: Type): (source)

Store best known type for variable if type inference failed. If a program ignores error on type inference error, the variable should get some inferred type so that if can used later on in the program. Example: x = [] # type: ignore x.append(1) # Should be ok! We implement this here by giving x a valid type (replacing inferred <nothing> with Any).

def set_inferred_type(self, var: Var, lvalue: Lvalue, type: Type): (source)

Store inferred variable type. Store the type to both the variable node and the expression node that refers to the variable (lvalue). If var is None, do nothing.

def should_report_unreachable_issues(self) -> bool: (source)

Undocumented

def simple_rvalue(self, rvalue: Expression) -> bool: (source)

Returns True for expressions for which inferred type should not depend on context. Note that this function can still return False for some expressions where inferred type does not depend on context. It only exists for performance optimizations.

def split_around_star(self, items: list[T], star_index: int, length: int) -> tuple[list[T], list[T], list[T]]: (source)

Splits a list of items in three to match another list of length 'length' that contains a starred expression at 'star_index' in the following way: star_index = 2, length = 5 (i.e., [a,b,*,c,d]), items = [1,2,3,4,5,6,7] returns in: ([1,2], [3,4,5], [6,7])

def store_type(self, node: Expression, typ: Type): (source)

Store the type of a node in the type map.

def store_types(self, d: dict[Expression, Type]): (source)

Undocumented

def str_type(self) -> Instance: (source)

Return instance type 'str'.

def temp_node(self, t: Type, context: Context|None = None) -> TempNode: (source)

Create a temporary node with the given, fixed type.

def try_infer_partial_generic_type_from_assignment(self, lvalue: Lvalue, rvalue: Expression, op: str): (source)

Try to infer a precise type for partial generic type from assignment. 'op' is '=' for normal assignment and a binary operator ('+', ...) for augmented assignment. Example where this happens: x = [] if foo(): x = [1] # Infer List[int] as type of 'x'

def try_infer_partial_type_from_indexed_assignment(self, lvalue: IndexExpr, rvalue: Expression): (source)

Undocumented

def type_check_raise(self, e: Expression, s: RaiseStmt, optional: bool = False): (source)

Undocumented

def type_is_iterable(self, type: Type) -> bool: (source)

Undocumented

def type_requires_usage(self, typ: Type) -> tuple[str, ErrorCode]|None: (source)

Some types require usage in all cases. The classic example is an unused coroutine. In the case that it does require usage, returns a note to attach to the error message.

def type_type(self) -> Instance: (source)

Return instance type 'type'.

def visit_assert_stmt(self, s: AssertStmt): (source)
def visit_assignment_stmt(self, s: AssignmentStmt): (source)

Type check an assignment statement. Handle all kinds of assignment statements (simple, indexed, multiple).

def visit_block(self, b: Block): (source)

Undocumented

def visit_break_stmt(self, s: BreakStmt): (source)
def visit_class_def(self, defn: ClassDef): (source)

Type check a class definition.

def visit_continue_stmt(self, s: ContinueStmt): (source)
def visit_decorator(self, e: Decorator): (source)
def visit_del_stmt(self, s: DelStmt): (source)
def visit_expression_stmt(self, s: ExpressionStmt): (source)
def visit_for_stmt(self, s: ForStmt): (source)

Type check a for statement.

def visit_func_def(self, defn: FuncDef): (source)
def visit_if_stmt(self, s: IfStmt): (source)

Type check an if statement.

def visit_import(self, node: Import): (source)

Undocumented

def visit_import_all(self, node: ImportAll): (source)
def visit_import_from(self, node: ImportFrom): (source)
def visit_match_stmt(self, s: MatchStmt): (source)
def visit_operator_assignment_stmt(self, s: OperatorAssignmentStmt): (source)

Type check an operator assignment statement, e.g. x += 1.

def visit_overloaded_func_def(self, defn: OverloadedFuncDef): (source)
def visit_raise_stmt(self, s: RaiseStmt): (source)

Type check a raise statement.

def visit_return_stmt(self, s: ReturnStmt): (source)

Type check a return statement.

def visit_try_stmt(self, s: TryStmt): (source)

Type check a try statement.

def visit_try_without_finally(self, s: TryStmt, try_frame: bool): (source)

Type check a try statement, ignoring the finally block. On entry, the top frame should receive all flow that exits the try block abnormally (i.e., such that the else block does not execute), and its parent should receive all flow that exits the try block normally.

def visit_while_stmt(self, s: WhileStmt): (source)

Type check a while statement.

def visit_with_stmt(self, s: WithStmt): (source)
def wrap_exception_group(self, types: Sequence[Type]) -> Type: (source)

Transform except* variable type into an appropriate exception group.

partial_type_augmented_ops: set = (source)

Undocumented

Value
set([('builtins.list', '+'), ('builtins.set', '|')])
allow_abstract_call = (source)

Undocumented

Undocumented

checking_missing_await: bool = (source)

Undocumented

current_node_deferred: bool = (source)

Undocumented

deferred_nodes: list = (source)

Undocumented

dynamic_funcs: list = (source)

Undocumented

Undocumented

expr_checker = (source)

Undocumented

Undocumented

inferred_attribute_types = (source)

Undocumented

Undocumented

is_typeshed_stub = (source)

Undocumented

module_refs = (source)

Undocumented

Undocumented

no_partial_types: bool = (source)

Undocumented

partial_reported = (source)

Undocumented

partial_types: list = (source)

Undocumented

pass_num: int = (source)

Undocumented

pattern_checker = (source)

Undocumented

Undocumented

recurse_into_functions: bool = (source)

Undocumented

return_types: list = (source)

Undocumented

Undocumented

temp_type_map = (source)

Undocumented

Undocumented

Undocumented

var_decl_frames: dict = (source)

Undocumented

Return the type context of the plugin

def _check_for_truthy_type(self, t: Type, expr: Expression): (source)

Undocumented

def _is_truthy_type(self, t: ProperType) -> bool: (source)

Undocumented

def _visit_func_def(self, defn: FuncDef): (source)

Type check a function definition.

def _visit_overloaded_func_def(self, defn: OverloadedFuncDef): (source)

Undocumented

_is_final_def = (source)

Undocumented

_type_maps: list[dict] = (source)

Undocumented