Make is_complex_subscript() ignore list literals

This fixes catastrophically quadratic behavior on long lists.
This commit is contained in:
Łukasz Langa 2018-06-09 15:40:39 -07:00
parent 94ebcb5085
commit d240ca25ea
2 changed files with 11 additions and 8 deletions

View File

@ -812,6 +812,9 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md).
* fixed improper formatting of f-strings with quotes inside interpolated
expressions (#322)
* fixed unnecessary slowdown when long list literals where found in a file
### 18.6b2
* added `--config` (#65)

View File

@ -1256,18 +1256,18 @@ def remove_trailing_comma(self) -> None:
def is_complex_subscript(self, leaf: Leaf) -> bool:
"""Return True iff `leaf` is part of a slice with non-trivial exprs."""
open_lsqb = (
leaf if leaf.type == token.LSQB else self.bracket_tracker.get_open_lsqb()
)
open_lsqb = self.bracket_tracker.get_open_lsqb()
if open_lsqb is None:
return False
subscript_start = open_lsqb.next_sibling
if (
isinstance(subscript_start, Node)
and subscript_start.type == syms.subscriptlist
):
subscript_start = child_towards(subscript_start, leaf)
if isinstance(subscript_start, Node):
if subscript_start.type == syms.listmaker:
return False
if subscript_start.type == syms.subscriptlist:
subscript_start = child_towards(subscript_start, leaf)
return subscript_start is not None and any(
n.type in TEST_DESCENDANTS for n in subscript_start.pre_order()
)