PEP8 E203 error occurs in list slice

4.6k views Asked by At
buffer[start_index : start_index + nbytes]
path[1 + path.rfind('#') :]

In this case, an error occurs in pep8 library

But, In PEP8 Documentation ( https://www.python.org/dev/peps/pep-0008/#other-recommendations )

Yes:

> ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]

> ham[lower:upper], ham[lower:upper:], ham[lower::step] ham[lower+offset:upper+offset]
> ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
> ham[lower + offset : upper + offset]

No:

> ham[lower + offset:upper + offset] ham[1: 9], ham[1 :9], ham[1:9 :3]
> ham[lower : : upper] ham[ : upper]

I think the above code is fine, but I don't know what the problem is.

1

There are 1 answers

0
holdenweb On BEST ANSWER

The pep8 utility defines E203 as "whitespace before colon on list slice".

This is a stylistic rather than a syntatic error (i.e., the code will work as intended, but the style contravenes the PEP8 standard): as you can see, the PEP8 recommendations exclude spaces around the colons used in slicing. To remove the error rewrite the first line as

buffer[start_index:start_index + nbytes]

pep8 may or may not complain about the spaces round the + operator as well, I can't remember the recommendation on that.