Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
perf: deduplicatefast_container_type andfast_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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from6 commits
2f2c39148cb9e119f02607d9dcb60cc75eb48bc430ff26ebfb608a6646f78253aa94728882c800f560b3c2fd9faaf92439File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
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 | ||
| - 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 | ||
sterliakov marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| 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 | ||
| typ = self.accept(item) | ||
| if typ not in values: | ||
sterliakov marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| 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 | ||