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

Function match_generic_callables

mypy/join.py:747–761  ·  view source on GitHub ↗
(t: CallableType, s: CallableType)

Source from the content-addressed store, hash-verified

745
746
747def match_generic_callables(t: CallableType, s: CallableType) -> tuple[CallableType, CallableType]:
748 # The case where we combine/join/meet similar callables, situation where both are generic
749 # requires special care. A more principled solution may involve unify_generic_callable(),
750 # but it would have two problems:
751 # * This adds risk of infinite recursion: e.g. join -> unification -> solver -> join
752 # * Using unification is an incorrect thing for meets, as it "widens" the types
753 # Finally, this effectively falls back to an old behaviour before namespaces were added to
754 # type variables, and it worked relatively well.
755 max_len = max(len(t.variables), len(s.variables))
756 min_len = min(len(t.variables), len(s.variables))
757 if min_len == 0:
758 return t, s
759 new_ids = [TypeVarId.new(meta_level=0) for _ in range(max_len)]
760 # Note: this relies on variables being in order they appear in function definition.
761 return update_callable_ids(t, new_ids), update_callable_ids(s, new_ids)
762
763
764def join_similar_callables(t: CallableType, s: CallableType) -> CallableType:

Callers 3

meet_similar_callablesFunction · 0.90
join_similar_callablesFunction · 0.85

Calls 6

maxFunction · 0.85
lenFunction · 0.85
minFunction · 0.85
rangeClass · 0.85
update_callable_idsFunction · 0.85
newMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…