Commit d240ca25 authored by Łukasz Langa's avatar Łukasz Langa
Browse files

Make `is_complex_subscript()` ignore list literals

This fixes catastrophically quadratic behavior on long lists.
parent 94ebcb50
Loading
Loading
Loading
Loading
+3 −0
Changes for README.md: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -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)
+7 −7
Changes for black.py: 7 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -1256,17 +1256,17 @@ 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
        ):

        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()