Skip to content

Commit 2f2c391

Browse files
committed
Only do this for collection literals
1 parent 4a427e9 commit 2f2c391

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

mypy/checkexpr.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5079,10 +5079,19 @@ def fast_container_type(
50795079
self.resolved_type[e] = NoneType()
50805080
return None
50815081
values.append(self.accept(item))
5082-
vt = join.join_type_list(values)
5083-
if not allow_fast_container_literal(vt):
5084-
self.resolved_type[e] = NoneType()
5085-
return None
5082+
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
5086+
# inference cycle over it. This helps in pathological cases where items
5087+
# are complex overloads.
5088+
# https://github.com/python/mypy/issues/14718
5089+
vt = values[0]
5090+
else:
5091+
vt = join.join_type_list(values)
5092+
if not allow_fast_container_literal(vt):
5093+
self.resolved_type[e] = NoneType()
5094+
return None
50865095
ct = self.chk.named_generic_type(container_fullname, [vt])
50875096
self.resolved_type[e] = ct
50885097
return ct

0 commit comments

Comments
 (0)