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

autopep8 removes whitespace before array slice, creating code not compliant with PEP 8 #774

Open
hannob opened this issue Dec 11, 2024 · 0 comments

Comments

@hannob
Copy link

hannob commented Dec 11, 2024

In the code example below, autopep8 removes a whitespace before the ":" array slice operator, turning

    v = input[n * 16 : n * 16 + 15]

into

    v = input[n * 16: n * 16 + 15]

I believe this is a bug. According to the PEP 8 documentation here
https://peps.python.org/pep-0008/#whitespace-in-expressions-and-statements
it says:
"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)."


Python Code

#!/usr/bin/python3

def test(input, n):
    v = input[n * 16 : n * 16 + 15]
    return v

Command Line and Configuration

Command Line

$ autopep8 [file]

Your Environment

  • Python version: 3.12.8
  • autopep8 version: 2.3.1
  • Platform: linux
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