spulec / pep8ify

A library that modifies python source code to conform to pep8.
Apache License 2.0
118 stars 12 forks source link

pep8ify doesn't correct E231 missing whitespace after ',' #8

Closed PaulMcMillan closed 12 years ago

PaulMcMillan commented 12 years ago

pep8 complains about code with a trailing , in a list like so:

foo = [1,2,]

test.py:1:9: E231 missing whitespace after ','

pep8ify doesn't fix this.

PaulMcMillan commented 12 years ago

In fact, it seems to correct these instances in the wrong direction such that pep8 complains about them.

PaulMcMillan commented 12 years ago

I'd sorta lean towards the correction being to remove the trailing comma in the list, since the alternative of [1,2, ] is pretty ugly too. On the other hand, lists that have the closing ] on a separate line benefit from the trailing comma, so...

spulec commented 12 years ago

I think that however lists are handled should be the same as how tuples are handled. Removing the trailing comma creates an issue for (1,) so it seem that (1, ) is a better solution. That seems fairly ugly to me, but I strongly want to keep compatibility with pep8.

It actually looks like pep8 does not complain about (1, 2,) which seems like a bug on their part. The edge-case code for single element tuples is probably allowing too much.