Skip to content

Commit 0cdcbfd

Browse files
authored
Optimise and_conditional_maps when using meet (#22253)
Use the expression hash index already built Authored by Codex
1 parent 01877d7 commit 0cdcbfd

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

‎mypy/checker.py‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9064,7 +9064,10 @@ def and_conditional_maps(m1: TypeMap, m2: TypeMap, *, use_meet: bool = False) ->
90649064
result[e1] = m1[e1]
90659065
continue
90669066

9067-
if not use_meet:
9067+
if use_meet:
9068+
e2 = m2_exprs[e1_hash]
9069+
result[e1] = meet_types(m1[e1], m2[e2])
9070+
else:
90689071
# If use_meet=False and the same expression's type is refined by both conditions,
90699072
# we somewhat arbitrarily give precedence to m2, unless a) m1's value is Never, or
90709073
# b) m2's value is Any and m1 isn't a union that could have been narrowed to Any.
@@ -9081,14 +9084,6 @@ def and_conditional_maps(m1: TypeMap, m2: TypeMap, *, use_meet: bool = False) ->
90819084
):
90829085
result[e1] = t1
90839086

9084-
if use_meet:
9085-
# For now, meet common keys only if specifically requested.
9086-
# This is currently used for tuple types narrowing, where having
9087-
# a precise result is important.
9088-
for e1 in m1:
9089-
for e2 in m2:
9090-
if literal_hash(e1) == literal_hash(e2):
9091-
result[e1] = meet_types(m1[e1], m2[e2])
90929087
return result
90939088

90949089

0 commit comments

Comments
 (0)