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

Function or_conditional_maps

mypy/checker.py:8858–8881  ·  view source on GitHub ↗

Calculate what information we can learn from the truth of (e1 or e2) in terms of the information that we can learn from the truth of e1 and the truth of e2. If coalesce_any is True, consider Any a supertype when joining restrictions.

(m1: TypeMap, m2: TypeMap, *, coalesce_any: bool = False)

Source from the content-addressed store, hash-verified

8856
8857
8858def or_conditional_maps(m1: TypeMap, m2: TypeMap, *, coalesce_any: bool = False) -> TypeMap:
8859 """Calculate what information we can learn from the truth of (e1 or e2)
8860 in terms of the information that we can learn from the truth of e1 and
8861 the truth of e2. If coalesce_any is True, consider Any a supertype when
8862 joining restrictions.
8863 """
8864
8865 if is_unreachable_map(m1):
8866 return m2
8867 if is_unreachable_map(m2):
8868 return m1
8869 # Both conditions can be true. Combine information about
8870 # expressions whose type is refined by both conditions. (We do not
8871 # learn anything about expressions whose type is refined by only
8872 # one condition.)
8873 result: dict[Expression, Type] = {}
8874 for n1 in m1:
8875 for n2 in m2:
8876 if literal_hash(n1) == literal_hash(n2):
8877 if coalesce_any and isinstance(get_proper_type(m1[n1]), AnyType):
8878 result[n1] = m1[n1]
8879 else:
8880 result[n1] = make_simplified_union([m1[n1], m2[n2]])
8881 return result
8882
8883
8884def reduce_conditional_maps(

Callers 4

visit_match_stmtMethod · 0.85
reduce_conditional_mapsFunction · 0.85

Calls 5

literal_hashFunction · 0.90
get_proper_typeFunction · 0.90
make_simplified_unionFunction · 0.90
is_unreachable_mapFunction · 0.85
isinstanceFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…