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

Function is_better

mypy/join.py:690–706  ·  view source on GitHub ↗
(t: Type, s: Type)

Source from the content-addressed store, hash-verified

688
689
690def is_better(t: Type, s: Type) -> bool:
691 # Given two possible results from join_instances_via_supertype(),
692 # indicate whether t is the better one.
693 t = get_proper_type(t)
694 s = get_proper_type(s)
695
696 if isinstance(t, Instance):
697 if not isinstance(s, Instance):
698 return True
699 if t.type.is_protocol != s.type.is_protocol:
700 if t.type.fullname != "builtins.object" and s.type.fullname != "builtins.object":
701 # mro of protocol is not really relevant
702 return not t.type.is_protocol
703 # Use len(mro) as a proxy for the better choice.
704 if len(t.type.mro) > len(s.type.mro):
705 return True
706 return False
707
708
709def normalize_callables(s: ProperType, t: ProperType) -> tuple[ProperType, ProperType]:

Callers 2

visit_instanceMethod · 0.85

Calls 3

get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…