From: Ɓukasz Langa Date: Fri, 16 Mar 2018 06:39:45 +0000 (-0700) Subject: Fix numpy-style array indexing X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/fb84d8b2ee524a9b3bff51fa35054abb44740f1d?ds=inline Fix numpy-style array indexing Fixes #33 --- diff --git a/black.py b/black.py index 51b5b21..d011483 100644 --- a/black.py +++ b/black.py @@ -960,7 +960,14 @@ def whitespace(leaf: Leaf) -> str: elif p.type == syms.subscript: # indexing - if not prev or prev.type == token.COLON: + if not prev: + assert p.parent is not None, "subscripts are always parented" + if p.parent.type == syms.subscriptlist: + return SPACE + + return NO + + elif prev.type == token.COLON: return NO elif p.type == syms.atom: diff --git a/tests/expression.py b/tests/expression.py index a3c810e..30a20e9 100644 --- a/tests/expression.py +++ b/tests/expression.py @@ -88,6 +88,7 @@ slice[:] slice[:-1] slice[1:] slice[::-1] +numpy[:, 0:1] (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None) {'2.7': dead, '3.7': long_live or die_hard} {'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'} @@ -219,6 +220,7 @@ slice[:] slice[:-1] slice[1:] slice[::-1] +numpy[:, 0:1] (str or None) if (sys.version_info[0] > (3,)) else (str or bytes or None) {'2.7': dead, '3.7': long_live or die_hard} {'2.7', '3.6', '3.7', '3.8', '3.9', '4.0' if gilectomy else '3.10'}