From: Ɓukasz Langa Date: Sat, 9 Jun 2018 22:40:39 +0000 (-0700) Subject: Make `is_complex_subscript()` ignore list literals X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/d240ca25ea73dad793750977fb7b7cdfbeadd2eb?ds=sidebyside;hp=94ebcb50851e40cba88c6ad2c14f9dfe45e08921 Make `is_complex_subscript()` ignore list literals This fixes catastrophically quadratic behavior on long lists. --- diff --git a/README.md b/README.md index 533a1f8..440f42b 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/black.py b/black.py index 35daaa9..a405bad 100644 --- a/black.py +++ b/black.py @@ -1256,18 +1256,18 @@ class Line: 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() )