MCPcopy Index your code
hub / github.com/python/mypy / can_match_sequence

Method can_match_sequence

mypy/checkpattern.py:771–783  ·  view source on GitHub ↗
(self, typ: ProperType)

Source from the content-addressed store, hash-verified

769 return False
770
771 def can_match_sequence(self, typ: ProperType) -> bool:
772 if isinstance(typ, AnyType):
773 return True
774 if isinstance(typ, UnionType):
775 return any(self.can_match_sequence(get_proper_type(item)) for item in typ.items)
776 for other in self.non_sequence_match_types:
777 # We have to ignore promotions, as memoryview should match, but bytes,
778 # which it can be promoted to, shouldn't
779 if is_subtype(typ, other, ignore_promotions=True):
780 return False
781 sequence = self.chk.named_type("typing.Sequence")
782 # If the static type is more general than sequence the actual type could still match
783 return is_subtype(typ, sequence) or is_subtype(sequence, typ)
784
785 def generate_types_from_names(self, type_names: list[str]) -> list[Type]:
786 types: list[Type] = []

Callers 2

Calls 5

get_proper_typeFunction · 0.90
is_subtypeFunction · 0.90
isinstanceFunction · 0.85
anyFunction · 0.85
named_typeMethod · 0.45

Tested by

no test coverage detected