Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slicing with omitted operand is not formatted according to PEP 8 #194

Closed
terrelln opened this issue May 7, 2018 · 1 comment
Closed

Comments

@terrelln
Copy link

terrelln commented May 7, 2018

Black suggests putting a space before the slice operator when the LHS has an operator but the RHS is omitted, which looks like it doesn't comply with PEP-8 (emphasis mine):

However, in a slice the colon acts like a binary operator, and should have equal amounts on either side (treating it as the operator with the lowest priority). In an extended slice, both colons must have the same amount of spacing applied. Exception: when a slice parameter is omitted, the space is omitted.

Looks like it was introduced by PR #178.

Python version: 3.6
Black version: black, version 18.4a5
Does also happen on master: yes

$ cat test.py
x = "hello"
x[0 + -1:]
$ black --diff test.py
--- test.py  (original)
+++ test.py  (formatted)
@@ -1,3 +1,3 @@
 x = "hello"
-x[0 + -1:]
+x[0 + -1 :]

reformatted test.py
@terrelln
Copy link
Author

terrelln commented May 8, 2018

I misunderstood the PEP 8 wording. The space is omitted on the RHS in the example, which is what the exception was referring to.

Seems a bit strange, but I'll get used to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant