Skip to content

Commit efd68dd

Browse files
ilevkivskyiJukkaL
authored andcommitted
New semantic analyzer: Copy, don't modify, unanalyzed types (#7094)
Fixes #6951.
1 parent cded69d commit efd68dd

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mypy/newsemanal/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3131,7 +3131,7 @@ def visit_with_stmt(self, s: WithStmt) -> None:
31313131
elif isinstance(s.unanalyzed_type, TupleType):
31323132
# We have multiple targets and multiple types
31333133
if len(actual_targets) == len(s.unanalyzed_type.items):
3134-
types = s.unanalyzed_type.items
3134+
types = s.unanalyzed_type.items.copy()
31353135
else:
31363136
# But it's the wrong number of items
31373137
self.fail('Incompatible number of types for `with` targets', s)

test-data/unit/check-newsemanal.test

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,6 +2717,16 @@ class N(NamedTuple):
27172717
b
27182718
[builtins fixtures/tuple.pyi]
27192719

2720+
[case testWithMultipleTargetsDeferred]
2721+
a: A
2722+
2723+
class A:
2724+
def __enter__(self) -> int: pass
2725+
def __exit__(self, x, y, z): pass
2726+
2727+
with A() as x, A() as y: # type: int, int
2728+
pass
2729+
27202730
[case testNewAnalyzerLessErrorsNeedAnnotation]
27212731
from typing import TypeVar, Optional
27222732

0 commit comments

Comments
 (0)