Skip to content

Commit 30c0e32

Browse files
committed
Retain original arg if possible
1 parent fdab830 commit 30c0e32

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

mypy/checkexpr.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4195,11 +4195,17 @@ def check_op(
41954195
# We don't do the same for the base expression because it could lead to weird
41964196
# type inference errors -- e.g. see 'testOperatorDoubleUnionSum'.
41974197
# TODO: Can we use `type_overrides_set()` here?
4198-
right_variants = [
4199-
(item, TempNode(item, context=context))
4200-
for item in self._union_items_from_typevar(right_type)
4201-
]
4202-
right_type = get_proper_type(right_type)
4198+
right_variants: list[tuple[Type, Expression]]
4199+
p_right = get_proper_type(right_type)
4200+
if isinstance(p_right, (UnionType, TypeVarType)):
4201+
right_variants = [
4202+
(item, TempNode(item, context=context))
4203+
for item in self._union_items_from_typevar(right_type)
4204+
]
4205+
else:
4206+
# Preserve argument identity if we do not intend to modify it
4207+
right_variants = [(right_type, arg)]
4208+
right_type = p_right
42034209

42044210
all_results = []
42054211
all_inferred = []

0 commit comments

Comments
 (0)