pycodestyle icon indicating copy to clipboard operation
pycodestyle copied to clipboard

Fix false alarm in E203 rule (issue #373, black incompatibility)

Open DesbyP opened this issue 5 years ago • 19 comments

Issue #373

Rule E203 checks for extraneous whitespace before a colon. Yet there is a corner case when the colon is used as a "slice" operator. PEP8 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). In an extended slice, both colons must have the same amount of spacing applied.

This behaviour isn't implemented and leads to conflict between pycodestyle and black.

Solution

This PR adds to pycodestyle the tolerance for the slice situation, without enforcing the "same amount of space on both sides of the colon" rule. This way the current Python that code was pycodestyle compliant stays compliant.

Performance

On a Python code base of over 15k lines, a test with hyperfine shows no performance loss.

DesbyP avatar Feb 28 '20 17:02 DesbyP