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

Method should_self_match

mypy/checkpattern.py:756–769  ·  view source on GitHub ↗
(self, typ: Type)

Source from the content-addressed store, hash-verified

754 return None
755
756 def should_self_match(self, typ: Type) -> bool:
757 typ = get_proper_type(typ)
758 if isinstance(typ, TupleType):
759 typ = typ.partial_fallback
760 if isinstance(typ, AnyType):
761 return False
762 if isinstance(typ, Instance) and typ.type.get("__match_args__") is not None:
763 # Named tuples and other subtypes of builtins that define __match_args__
764 # should not self match.
765 return False
766 for other in self.self_match_types:
767 if is_subtype(typ, other):
768 return True
769 return False
770
771 def can_match_sequence(self, typ: ProperType) -> bool:
772 if isinstance(typ, AnyType):

Callers 1

visit_class_patternMethod · 0.95

Calls 4

get_proper_typeFunction · 0.90
is_subtypeFunction · 0.90
isinstanceFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected