-
-
Notifications
You must be signed in to change notification settings - Fork 3k
perf: deduplicate fast_container_type
and fast_dict_type
items before joining
#19409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
2f2c391
48cb9e1
19f0260
7d9dcb6
0cc75eb
48bc430
ff26ebf
b608a66
46f7825
3aa9472
8882c80
0f560b3
c2fd9fa
af92439
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5064,11 +5064,16 @@ def fast_container_type( | |
Limitations: | ||
- no active type context | ||
- no star expressions | ||
- the joined type of all entries must be an Instance or Tuple type | ||
- not after deferral | ||
- either exactly one distinct type inside, | ||
or the joined type of all entries must be an Instance or Tuple type | ||
""" | ||
ctx = self.type_context[-1] | ||
if ctx: | ||
return None | ||
if self.chk.current_node_deferred: | ||
# Guarantees that all items will be Any, we'll reject it anyway. | ||
return None | ||
rt = self.resolved_type.get(e, None) | ||
if rt is not None: | ||
return rt if isinstance(rt, Instance) else None | ||
|
@@ -5078,11 +5083,22 @@ def fast_container_type( | |
# fallback to slow path | ||
self.resolved_type[e] = NoneType() | ||
return None | ||
values.append(self.accept(item)) | ||
vt = join.join_type_list(values) | ||
if not allow_fast_container_literal(vt): | ||
self.resolved_type[e] = NoneType() | ||
return None | ||
|
||
typ = self.accept(item) | ||
if typ not in values: | ||
sterliakov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
values.append(typ) | ||
|
||
if len(values) == 1 and not self.chk.current_node_deferred: | ||
|
||
# If only one non-duplicate item remains, there's no need to run the whole | ||
# inference cycle over it. This helps in pathological cases where items | ||
# are complex overloads. | ||
# https://github.com/python/mypy/issues/14718 | ||
vt = values[0] | ||
else: | ||
vt = join.join_type_list(values) | ||
if not allow_fast_container_literal(vt): | ||
self.resolved_type[e] = NoneType() | ||
return None | ||
ct = self.chk.named_generic_type(container_fullname, [vt]) | ||
self.resolved_type[e] = ct | ||
return ct | ||
|
Uh oh!
There was an error while loading. Please reload this page.