Skip to content

E203 fix should leave equal amounts of space on either side of a slice operator #7259

@bersbersbers

Description

@bersbersbers
ham[lower + offset : upper + offset]

ruff --fix --select E203 bug.py (v0.0.287) gives

ham[lower + offset: upper + offset]

which is discouraged by PEP 8:

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

https://peps.python.org/pep-0008/#pet-peeves

So, ham[lower + offset: upper + offset] is incorrect. I would argue that ham[lower + offset : upper + offset] (which is what black outputs) should not be flagged by E203; and if so, both spaces should be removed (but I still argue to remove none at all).

Metadata

Metadata

Assignees

Labels

acceptedReady for implementationruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions