class documentation

class MessageBuilder: (source)

View In Hierarchy

Helper class for reporting type checker error messages with parameters. The methods of this class need to be provided with the context within a file; the errors member manages the wider context. IDEA: Support a 'verbose mode' that includes full information about types in error messages and that may otherwise produce more detailed error messages.

Method __init__ Undocumented
Method add_errors Add errors in messages to this builder.
Method add_fixture_note Undocumented
Method annotation_in_unchecked_function Undocumented
Method are_type_names_disabled Undocumented
Method argument_incompatible_with_supertype Undocumented
Method assert_type_fail Undocumented
Method bad_proto_variance Undocumented
Method base_class_definitions_incompatible Undocumented
Method cannot_determine_type Undocumented
Method cannot_determine_type_in_base Undocumented
Method cannot_instantiate_abstract_class Undocumented
Method cannot_use_function_with_type Undocumented
Method cant_assign_to_classvar Undocumented
Method cant_assign_to_final Warn about a prohibited assignment to a final attribute.
Method cant_assign_to_method Undocumented
Method cant_override_final Undocumented
Method comparison_method_example_msg Undocumented
Method concrete_only_assign Undocumented
Method concrete_only_call Undocumented
Method could_not_infer_type_arguments Undocumented
Method dangerous_comparison Undocumented
Method deleted_as_lvalue Report an error about using an deleted type as an lvalue.
Method deleted_as_rvalue Report an error about using an deleted type as an rvalue.
Method disable_type_names Undocumented
Method disallowed_any_type Undocumented
Method does_not_return_value Report an error about use of an unusable type.
Method duplicate_argument_value Undocumented
Method explicit_any Undocumented
Method fail Report an error message (unless disabled).
Method filter_errors Undocumented
Method final_cant_override_writable Undocumented
Method final_without_value Undocumented
Method first_argument_for_super_must_be_type Undocumented
Method format_long_tuple_type Format very long tuple type using an ellipsis notation
Method forward_operator_not_callable Undocumented
Method generate_incompatible_tuple_error Generate error message for individual incompatible tuple pairs
Method has_no_attr Report a missing or non-accessible member.
Method impossible_intersection Undocumented
Method incompatible_argument Report an error about an incompatible argument type.
Method incompatible_argument_note Undocumented
Method incompatible_conditional_function_def Undocumented
Method incompatible_operator_assignment Undocumented
Method incompatible_self_argument Undocumented
Method incompatible_type_application Undocumented
Method incompatible_typevar_value Undocumented
Method incorrect__exit__return Undocumented
Method incorrectly_returning_any Undocumented
Method invalid_index_type Undocumented
Method invalid_keyword_var_arg Undocumented
Method invalid_signature Undocumented
Method invalid_signature_for_special_method Undocumented
Method invalid_var_arg Undocumented
Method key_not_in_mapping Undocumented
Method maybe_note_about_special_args Undocumented
Method maybe_note_concatenate_pos_args Undocumented
Method missing_named_argument Undocumented
Method need_annotation_for_var Undocumented
Method no_formal_self Undocumented
Method no_variant_matches_arguments Undocumented
Method not_callable Undocumented
Method note Report a note (unless disabled).
Method note_call Undocumented
Method note_multiline Report as many notes as lines in the message (unless disabled).
Method operator_method_signatures_overlap Undocumented
Method overload_inconsistently_applies_decorator Undocumented
Method overload_signature_incompatible_with_supertype Undocumented
Method overloaded_signature_will_never_match Undocumented
Method overloaded_signatures_arg_specific Undocumented
Method overloaded_signatures_overlap Undocumented
Method overloaded_signatures_ret_specific Undocumented
Method overloaded_signatures_typevar_specific Undocumented
Method override_target Undocumented
Method possible_missing_await Undocumented
Method prefer_simple_messages Should we generate simple/fast error messages?
Method pretty_callable_or_overload Undocumented
Method pretty_overload Undocumented
Method print_more Undocumented
Method protocol_members_cant_be_final Undocumented
Method read_only_property Undocumented
Method redundant_cast Undocumented
Method redundant_condition_in_comprehension Undocumented
Method redundant_condition_in_if Undocumented
Method redundant_expr Undocumented
Method redundant_left_operand Indicates that the left operand of a boolean expression is redundant: it does not change the truth value of the entire condition as a whole. 'op_name' should either be the string "and" or the string "or".
Method report Report an error or note (unless disabled).
Method report_non_method_protocol Undocumented
Method report_protocol_problems Report possible protocol conflicts between 'subtype' and 'supertype'.
Method requires_int_or_char Undocumented
Method requires_int_or_single_byte Undocumented
Method return_type_incompatible_with_supertype Undocumented
Method reveal_locals Undocumented
Method reveal_type Undocumented
Method signature_incompatible_with_supertype Undocumented
Method signatures_incompatible Undocumented
Method string_interpolation_mixing_key_and_non_keys Undocumented
Method string_interpolation_with_star_and_key Undocumented
Method too_few_arguments Undocumented
Method too_few_string_formatting_arguments Undocumented
Method too_many_arguments Undocumented
Method too_many_arguments_from_typed_dict Undocumented
Method too_many_positional_arguments Undocumented
Method too_many_string_formatting_arguments Undocumented
Method try_report_long_tuple_assignment_error Try to generate meaningful error message for very long tuple assignment
Method type_arguments_not_allowed Undocumented
Method type_not_iterable Undocumented
Method typed_function_untyped_decorator Undocumented
Method typeddict_context_ambiguous Undocumented
Method typeddict_key_cannot_be_deleted Undocumented
Method typeddict_key_must_be_string_literal Undocumented
Method typeddict_key_not_found Handle error messages for TypedDicts that have unknown keys.
Method typeddict_setdefault_arguments_inconsistent Undocumented
Method undefined_in_superclass Undocumented
Method unexpected_keyword_argument Undocumented
Method unexpected_typeddict_keys Undocumented
Method unimported_type_becomes_any Undocumented
Method unpacking_strings_disallowed Undocumented
Method unreachable_right_operand Indicates that the right operand of a boolean expression is redundant: it does not change the truth value of the entire condition as a whole. 'op_name' should either be the string "and" or the string "or".
Method unreachable_statement Undocumented
Method unsafe_super Undocumented
Method unsupported_left_operand Undocumented
Method unsupported_operand_types Report unsupported operand types for a binary operation.
Method unsupported_placeholder Undocumented
Method unsupported_type_type Undocumented
Method untyped_decorated_function Undocumented
Method untyped_function_call Undocumented
Method var_used_before_def Undocumented
Method variable_may_be_undefined Undocumented
Method warn_both_operands_are_from_unions Undocumented
Method warn_operand_was_from_union Undocumented
Method wrong_number_values_to_unpack Undocumented
Method yield_from_invalid_operand_type Undocumented
Instance Variable errors Undocumented
Instance Variable modules Undocumented
Instance Variable _disable_type_names Undocumented
def __init__(self, errors: Errors, modules: dict[str, MypyFile]): (source)

Undocumented

def add_errors(self, errors: list[ErrorInfo]): (source)

Add errors in messages to this builder.

def add_fixture_note(self, fullname: str, ctx: Context): (source)

Undocumented

def annotation_in_unchecked_function(self, context: Context): (source)

Undocumented

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

Undocumented

def argument_incompatible_with_supertype(self, arg_num: int, name: str, type_name: str|None, name_in_supertype: str, arg_type_in_supertype: Type, supertype: str, context: Context, secondary_context: Context): (source)

Undocumented

def assert_type_fail(self, source_type: Type, target_type: Type, context: Context): (source)

Undocumented

def bad_proto_variance(self, actual: int, tvar_name: str, expected: int, context: Context): (source)

Undocumented

def base_class_definitions_incompatible(self, name: str, base1: TypeInfo, base2: TypeInfo, context: Context): (source)

Undocumented

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

Undocumented

def cannot_determine_type_in_base(self, name: str, base: str, context: Context): (source)

Undocumented

def cannot_instantiate_abstract_class(self, class_name: str, abstract_attributes: dict[str, bool], context: Context): (source)

Undocumented

def cannot_use_function_with_type(self, method_name: str, type_name: str, context: Context): (source)

Undocumented

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

Undocumented

def cant_assign_to_final(self, name: str, attr_assign: bool, ctx: Context): (source)

Warn about a prohibited assignment to a final attribute. Pass `attr_assign=True` if the assignment assigns to an attribute.

def cant_assign_to_method(self, context: Context): (source)

Undocumented

def cant_override_final(self, name: str, base_name: str, ctx: Context): (source)

Undocumented

def comparison_method_example_msg(self, class_name: str) -> str: (source)

Undocumented

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

Undocumented

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

Undocumented

def could_not_infer_type_arguments(self, callee_type: CallableType, n: int, context: Context): (source)

Undocumented

def dangerous_comparison(self, left: Type, right: Type, kind: str, ctx: Context): (source)

Undocumented

def deleted_as_lvalue(self, typ: DeletedType, context: Context): (source)

Report an error about using an deleted type as an lvalue. Currently, this only occurs when trying to assign to an exception variable outside the local except: blocks.

def deleted_as_rvalue(self, typ: DeletedType, context: Context): (source)

Report an error about using an deleted type as an rvalue.

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

Undocumented

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

Undocumented

def does_not_return_value(self, callee_type: Type|None, context: Context): (source)

Report an error about use of an unusable type.

def duplicate_argument_value(self, callee: CallableType, index: int, context: Context): (source)

Undocumented

def explicit_any(self, ctx: Context): (source)

Undocumented

def fail(self, msg: str, context: Context|None, *, code: ErrorCode|None = None, file: str|None = None, allow_dups: bool = False, secondary_context: Context|None = None): (source)

Report an error message (unless disabled).

def filter_errors(self, *, filter_errors: bool|Callable[[str, ErrorInfo], bool] = True, save_filtered_errors: bool = False) -> ErrorWatcher: (source)

Undocumented

def final_cant_override_writable(self, name: str, ctx: Context): (source)

Undocumented

def final_without_value(self, ctx: Context): (source)

Undocumented

def first_argument_for_super_must_be_type(self, actual: Type, context: Context): (source)

Undocumented

def format_long_tuple_type(self, typ: TupleType) -> str: (source)

Format very long tuple type using an ellipsis notation

def forward_operator_not_callable(self, forward_method: str, context: Context): (source)

Undocumented

def generate_incompatible_tuple_error(self, lhs_types: list[Type], rhs_types: list[Type], context: Context, msg: message_registry.ErrorMessage): (source)

Generate error message for individual incompatible tuple pairs

def has_no_attr(self, original_type: Type, typ: Type, member: str, context: Context, module_symbol_table: SymbolTable|None = None) -> Type: (source)

Report a missing or non-accessible member. original_type is the top-level type on which the error occurred. typ is the actual type that is missing the member. These can be different, e.g., in a union, original_type will be the union and typ will be the specific item in the union that does not have the member attribute. 'module_symbol_table' is passed to this function if the type for which we are trying to get a member was originally a module. The SymbolTable allows us to look up and suggests attributes of the module since they are not directly available on original_type If member corresponds to an operator, use the corresponding operator name in the messages. Return type Any.

def impossible_intersection(self, formatted_base_class_list: str, reason: str, context: Context): (source)

Undocumented

def incompatible_argument(self, n: int, m: int, callee: CallableType, arg_type: Type, arg_kind: ArgKind, object_type: Type|None, context: Context, outer_context: Context) -> ErrorCode|None: (source)

Report an error about an incompatible argument type. The argument type is arg_type, argument number is n and the callee type is 'callee'. If the callee represents a method that corresponds to an operator, use the corresponding operator name in the messages. Return the error code that used for the argument (multiple error codes are possible).

def incompatible_argument_note(self, original_caller_type: ProperType, callee_type: ProperType, context: Context, code: ErrorCode|None): (source)

Undocumented

def incompatible_conditional_function_def(self, defn: FuncDef, old_type: FunctionLike, new_type: FunctionLike): (source)

Undocumented

def incompatible_operator_assignment(self, op: str, context: Context): (source)

Undocumented

def incompatible_self_argument(self, name: str, arg: Type, sig: CallableType, is_classmethod: bool, context: Context): (source)

Undocumented

def incompatible_type_application(self, expected_arg_count: int, actual_arg_count: int, context: Context): (source)

Undocumented

def incompatible_typevar_value(self, callee: CallableType, typ: Type, typevar_name: str, context: Context): (source)

Undocumented

def incorrect__exit__return(self, context: Context): (source)

Undocumented

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

Undocumented

def invalid_index_type(self, index_type: Type, expected_type: Type, base_str: str, context: Context, *, code: ErrorCode): (source)

Undocumented

def invalid_keyword_var_arg(self, typ: Type, is_mapping: bool, context: Context): (source)

Undocumented

def invalid_signature(self, func_type: Type, context: Context): (source)

Undocumented

def invalid_signature_for_special_method(self, func_type: Type, context: Context, method_name: str): (source)

Undocumented

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

Undocumented

def key_not_in_mapping(self, key: str, context: Context): (source)

Undocumented

def maybe_note_about_special_args(self, callee: CallableType, context: Context): (source)

Undocumented

def maybe_note_concatenate_pos_args(self, original_caller_type: ProperType, callee_type: ProperType, context: Context, code: ErrorCode|None = None): (source)

Undocumented

def missing_named_argument(self, callee: CallableType, context: Context, name: str): (source)

Undocumented

def need_annotation_for_var(self, node: SymbolNode, context: Context, python_version: tuple[int, int]|None = None): (source)

Undocumented

def no_formal_self(self, name: str, item: CallableType, context: Context): (source)

Undocumented

def no_variant_matches_arguments(self, overload: Overloaded, arg_types: list[Type], context: Context, *, code: ErrorCode|None = None): (source)

Undocumented

def not_callable(self, typ: Type, context: Context) -> Type: (source)

Undocumented

def note(self, msg: str, context: Context, file: str|None = None, origin: Context|None = None, offset: int = 0, allow_dups: bool = False, *, code: ErrorCode|None = None, secondary_context: Context|None = None): (source)

Report a note (unless disabled).

def note_call(self, subtype: Type, call: Type, context: Context, *, code: ErrorCode|None): (source)

Undocumented

def note_multiline(self, messages: str, context: Context, file: str|None = None, offset: int = 0, allow_dups: bool = False, code: ErrorCode|None = None, *, secondary_context: Context|None = None): (source)

Report as many notes as lines in the message (unless disabled).

def operator_method_signatures_overlap(self, reverse_class: TypeInfo, reverse_method: str, forward_class: Type, forward_method: str, context: Context): (source)

Undocumented

def overload_inconsistently_applies_decorator(self, decorator: str, context: Context): (source)

Undocumented

def overload_signature_incompatible_with_supertype(self, name: str, name_in_super: str, supertype: str, context: Context): (source)

Undocumented

def overloaded_signature_will_never_match(self, index1: int, index2: int, context: Context): (source)

Undocumented

def overloaded_signatures_arg_specific(self, index: int, context: Context): (source)

Undocumented

def overloaded_signatures_overlap(self, index1: int, index2: int, context: Context): (source)

Undocumented

def overloaded_signatures_ret_specific(self, index: int, context: Context): (source)

Undocumented

def overloaded_signatures_typevar_specific(self, index: int, context: Context): (source)

Undocumented

def override_target(self, name: str, name_in_super: str, supertype: str) -> str: (source)

Undocumented

def possible_missing_await(self, context: Context): (source)

Undocumented

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

Should we generate simple/fast error messages? If errors aren't shown to the user, we don't want to waste cyles producing complex error messages.

def pretty_callable_or_overload(self, tp: CallableType|Overloaded, context: Context, *, offset: int = 0, add_class_or_static_decorator: bool = False, allow_dups: bool = False, code: ErrorCode|None = None): (source)

Undocumented

def pretty_overload(self, tp: Overloaded, context: Context, offset: int, *, add_class_or_static_decorator: bool = False, allow_dups: bool = False, code: ErrorCode|None = None, skip_self: bool = False): (source)

Undocumented

def print_more(self, conflicts: Sequence[Any], context: Context, offset: int, max_items: int, *, code: ErrorCode|None = None): (source)

Undocumented

def protocol_members_cant_be_final(self, ctx: Context): (source)

Undocumented

def read_only_property(self, name: str, type: TypeInfo, context: Context): (source)

Undocumented

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

Undocumented

def redundant_condition_in_comprehension(self, truthiness: bool, context: Context): (source)

Undocumented

def redundant_condition_in_if(self, truthiness: bool, context: Context): (source)

Undocumented

def redundant_expr(self, description: str, truthiness: bool, context: Context): (source)

Undocumented

def redundant_left_operand(self, op_name: str, context: Context): (source)

Indicates that the left operand of a boolean expression is redundant: it does not change the truth value of the entire condition as a whole. 'op_name' should either be the string "and" or the string "or".

def report(self, msg: str, context: Context|None, severity: str, *, code: ErrorCode|None = None, file: str|None = None, origin: Context|None = None, offset: int = 0, allow_dups: bool = False, secondary_context: Context|None = None): (source)

Report an error or note (unless disabled). Note that context controls where error is reported, while origin controls where # type: ignore comments have effect.

def report_non_method_protocol(self, tp: TypeInfo, members: list[str], context: Context): (source)

Undocumented

def report_protocol_problems(self, subtype: (((Instance|TupleType)|TypedDictType)|TypeType)|CallableType, supertype: Instance, context: Context, *, code: ErrorCode|None): (source)

Report possible protocol conflicts between 'subtype' and 'supertype'. This includes missing members, incompatible types, and incompatible attribute flags, such as settable vs read-only or class variable vs instance variable.

def requires_int_or_char(self, context: Context, format_call: bool = False): (source)

Undocumented

def requires_int_or_single_byte(self, context: Context, format_call: bool = False): (source)

Undocumented

def return_type_incompatible_with_supertype(self, name: str, name_in_supertype: str, supertype: str, original: Type, override: Type, context: Context): (source)

Undocumented

def reveal_locals(self, type_map: dict[str, Type|None], context: Context): (source)

Undocumented

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

Undocumented

def signature_incompatible_with_supertype(self, name: str, name_in_super: str, supertype: str, context: Context, original: FunctionLike|None = None, override: FunctionLike|None = None): (source)

Undocumented

def signatures_incompatible(self, method: str, other_method: str, context: Context): (source)

Undocumented

def string_interpolation_mixing_key_and_non_keys(self, context: Context): (source)

Undocumented

def string_interpolation_with_star_and_key(self, context: Context): (source)

Undocumented

def too_few_arguments(self, callee: CallableType, context: Context, argument_names: Sequence[str|None]|None): (source)

Undocumented

def too_few_string_formatting_arguments(self, context: Context): (source)

Undocumented

def too_many_arguments(self, callee: CallableType, context: Context): (source)

Undocumented

def too_many_arguments_from_typed_dict(self, callee: CallableType, arg_type: TypedDictType, context: Context): (source)

Undocumented

def too_many_positional_arguments(self, callee: CallableType, context: Context): (source)

Undocumented

def too_many_string_formatting_arguments(self, context: Context): (source)

Undocumented

def try_report_long_tuple_assignment_error(self, subtype: ProperType, supertype: ProperType, context: Context, msg: message_registry.ErrorMessage, subtype_label: str|None = None, supertype_label: str|None = None) -> bool: (source)

Try to generate meaningful error message for very long tuple assignment Returns a bool: True when generating long tuple assignment error, False when no such error reported

def type_arguments_not_allowed(self, context: Context): (source)

Undocumented

def type_not_iterable(self, type: Type, context: Context): (source)

Undocumented

def typed_function_untyped_decorator(self, func_name: str, context: Context): (source)

Undocumented

def typeddict_context_ambiguous(self, types: list[TypedDictType], context: Context): (source)

Undocumented

def typeddict_key_cannot_be_deleted(self, typ: TypedDictType, item_name: str, context: Context): (source)

Undocumented

def typeddict_key_must_be_string_literal(self, typ: TypedDictType, context: Context): (source)

Undocumented

def typeddict_key_not_found(self, typ: TypedDictType, item_name: str, context: Context, setitem: bool = False): (source)

Handle error messages for TypedDicts that have unknown keys. Note, that we differentiate in between reading a value and setting a value. Setting a value on a TypedDict is an 'unknown-key' error, whereas reading it is the more serious/general 'item' error.

def typeddict_setdefault_arguments_inconsistent(self, default: Type, expected: Type, context: Context): (source)

Undocumented

def undefined_in_superclass(self, member: str, context: Context): (source)

Undocumented

def unexpected_keyword_argument(self, callee: CallableType, name: str, arg_type: Type, context: Context): (source)

Undocumented

def unexpected_typeddict_keys(self, typ: TypedDictType, expected_keys: list[str], actual_keys: list[str], context: Context): (source)

Undocumented

def unimported_type_becomes_any(self, prefix: str, typ: Type, ctx: Context): (source)

Undocumented

def unpacking_strings_disallowed(self, context: Context): (source)

Undocumented

def unreachable_right_operand(self, op_name: str, context: Context): (source)

Indicates that the right operand of a boolean expression is redundant: it does not change the truth value of the entire condition as a whole. 'op_name' should either be the string "and" or the string "or".

def unreachable_statement(self, context: Context): (source)

Undocumented

def unsafe_super(self, method: str, cls: str, ctx: Context): (source)

Undocumented

def unsupported_left_operand(self, op: str, typ: Type, context: Context): (source)

Undocumented

def unsupported_operand_types(self, op: str, left_type: Any, right_type: Any, context: Context, *, code: ErrorCode = codes.OPERATOR): (source)

Report unsupported operand types for a binary operation. Types can be Type objects or strings.

def unsupported_placeholder(self, placeholder: str, context: Context): (source)

Undocumented

def unsupported_type_type(self, item: Type, context: Context): (source)

Undocumented

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

Undocumented

def untyped_function_call(self, callee: CallableType, context: Context) -> Type: (source)

Undocumented

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

Undocumented

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

Undocumented

def warn_both_operands_are_from_unions(self, context: Context): (source)

Undocumented

def warn_operand_was_from_union(self, side: str, original: Type, context: Context): (source)

Undocumented

def wrong_number_values_to_unpack(self, provided: int, expected: int, context: Context): (source)

Undocumented

def yield_from_invalid_operand_type(self, expr: Type, context: Context) -> Type: (source)

Undocumented

Undocumented

Undocumented

_disable_type_names: list = (source)

Undocumented