class documentation

Pattern checker. This class checks if a pattern can match a type, what the type can be narrowed to, and what type capture patterns should be inferred as.

Method __init__ Undocumented
Method accept Undocumented
Method can_match_sequence Undocumented
Method construct_sequence_child If outer_type is a child class of typing.Sequence returns a new instance of outer_type, that is a Sequence of inner_type. If outer_type is not a child class of typing.Sequence just returns a Sequence of inner_type...
Method contract_starred_pattern_types Contracts a list of types in a sequence pattern depending on the position of a starred capture pattern.
Method early_non_match Undocumented
Method expand_starred_pattern_types Undoes the contraction done by contract_starred_pattern_types.
Method generate_types_from_names Undocumented
Method get_mapping_item_type Undocumented
Method get_sequence_type Undocumented
Method get_simple_mapping_item_type Undocumented
Method should_self_match Undocumented
Method update_type_map Undocumented
Method visit_as_pattern Undocumented
Method visit_class_pattern Undocumented
Method visit_mapping_pattern Undocumented
Method visit_or_pattern Undocumented
Method visit_sequence_pattern Undocumented
Method visit_singleton_pattern Undocumented
Method visit_starred_pattern Undocumented
Method visit_value_pattern Undocumented
Class Variable subject Undocumented
Class Variable subject_type Undocumented
Instance Variable chk Undocumented
Instance Variable msg Undocumented
Instance Variable non_sequence_match_types Undocumented
Instance Variable plugin Undocumented
Instance Variable self_match_types Undocumented
Instance Variable type_context Undocumented
def __init__(self, chk: mypy.checker.TypeChecker, msg: MessageBuilder, plugin: Plugin): (source)

Undocumented

def accept(self, o: Pattern, type_context: Type) -> PatternType: (source)

Undocumented

def can_match_sequence(self, typ: ProperType) -> bool: (source)

Undocumented

def construct_sequence_child(self, outer_type: Type, inner_type: Type) -> Type: (source)

If outer_type is a child class of typing.Sequence returns a new instance of outer_type, that is a Sequence of inner_type. If outer_type is not a child class of typing.Sequence just returns a Sequence of inner_type For example: construct_sequence_child(List[int], str) = List[str] TODO: this doesn't make sense. For example if one has class S(Sequence[int], Generic[T]) or class T(Sequence[Tuple[T, T]]), there is no way any of those can map to Sequence[str].

def contract_starred_pattern_types(self, types: list[Type], star_pos: int|None, num_patterns: int) -> list[Type]: (source)

Contracts a list of types in a sequence pattern depending on the position of a starred capture pattern. For example if the sequence pattern [a, *b, c] is matched against types [bool, int, str, bytes] the contracted types are [bool, Union[int, str], bytes]. If star_pos in None the types are returned unchanged.

def early_non_match(self) -> PatternType: (source)

Undocumented

def expand_starred_pattern_types(self, types: list[Type], star_pos: int|None, num_types: int) -> list[Type]: (source)

Undoes the contraction done by contract_starred_pattern_types. For example if the sequence pattern is [a, *b, c] and types [bool, int, str] are extended to length 4 the result is [bool, int, int, str].

def generate_types_from_names(self, type_names: list[str]) -> list[Type]: (source)

Undocumented

def get_mapping_item_type(self, pattern: MappingPattern, mapping_type: Type, key: Expression) -> Type|None: (source)

Undocumented

def get_sequence_type(self, t: Type) -> Type|None: (source)

Undocumented

def get_simple_mapping_item_type(self, pattern: MappingPattern, mapping_type: Type, key: Expression) -> Type: (source)

Undocumented

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

Undocumented

def update_type_map(self, original_type_map: dict[Expression, Type], extra_type_map: dict[Expression, Type]): (source)

Undocumented

def visit_as_pattern(self, o: AsPattern) -> PatternType: (source)
def visit_class_pattern(self, o: ClassPattern) -> PatternType: (source)
def visit_mapping_pattern(self, o: MappingPattern) -> PatternType: (source)
def visit_or_pattern(self, o: OrPattern) -> PatternType: (source)
def visit_sequence_pattern(self, o: SequencePattern) -> PatternType: (source)
def visit_singleton_pattern(self, o: SingletonPattern) -> PatternType: (source)
def visit_starred_pattern(self, o: StarredPattern) -> PatternType: (source)
def visit_value_pattern(self, o: ValuePattern) -> PatternType: (source)

Undocumented

subject_type: Type = (source)

Undocumented

Undocumented

Undocumented

non_sequence_match_types = (source)

Undocumented

Undocumented

self_match_types = (source)

Undocumented

type_context: list = (source)

Undocumented