Skip to content

Commit 19f0260

Browse files
committed
Fix interaction with deferrals
1 parent 48cb9e1 commit 19f0260

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

mypy/checkexpr.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5064,11 +5064,16 @@ def fast_container_type(
50645064
Limitations:
50655065
- no active type context
50665066
- no star expressions
5067-
- the joined type of all entries must be an Instance or Tuple type
5067+
- not after deferral
5068+
- either exactly one distinct type inside,
5069+
or the joined type of all entries must be an Instance or Tuple type
50685070
"""
50695071
ctx = self.type_context[-1]
50705072
if ctx:
50715073
return None
5074+
if self.chk.current_node_deferred:
5075+
# Guarantees that all items will be Any, we'll reject it anyway.
5076+
return None
50725077
rt = self.resolved_type.get(e, None)
50735078
if rt is not None:
50745079
return rt if isinstance(rt, Instance) else None
@@ -5078,11 +5083,13 @@ def fast_container_type(
50785083
# fallback to slow path
50795084
self.resolved_type[e] = NoneType()
50805085
return None
5081-
values.append(self.accept(item))
50825086

5083-
values = [v for i, v in enumerate(values) if v not in values[:i]]
5084-
if len(values) == 1:
5085-
# If only one non-duplicate item remains, there's no need running whole
5087+
typ = self.accept(item)
5088+
if typ not in values:
5089+
values.append(typ)
5090+
5091+
if len(values) == 1 and not self.chk.current_node_deferred:
5092+
# If only one non-duplicate item remains, there's no need to run the whole
50865093
# inference cycle over it. This helps in pathological cases where items
50875094
# are complex overloads.
50885095
# https://github.com/python/mypy/issues/14718

0 commit comments

Comments
 (0)