You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
E231: Check misses trailing comma in function or class calls that do not end with whitespace #980
Trailing commas in function calls, e.g. print(1,2,) that do not end with a white space are not flagged by pycodestyle.
From reading the corresponding PEP8 I would expect that pycodestyle would flag this.
pycodestyle is an old tool and pep8 changes a lot so they're not always in sync (and even when they could be, sometimes pep8 has flip-flopped on an issue or is directly contradictory with itself so it's impossible to follow to a T). this particular part of pep8 is relatively new (2017) and so it's not surprising that pycodestyle has nothing for it.
additionally it's tricky to get correct, in your example print(1, 2,) it's hard to know whether this is a tuple or function call (since pycodestyle does not access the parse tree for performance reasons).
you might be interested in some tools which are built around handling these such as add-trailing-comma or black -- both of which are probably better suited to handle this than pycodestyle is
Thanks for the reply and also for the hints towards the plugin. I'll have a look.
Ironically, I was stumbling over this while using flake8, which, I am assuming, uses pycodestyle, in conjunction with black (which produces these kind of lines under certain circumstances, at least for the version I am using. But that does not belong here.).
Activity
asottile commentedon Feb 24, 2021
pycodestyle is an old tool and pep8 changes a lot so they're not always in sync (and even when they could be, sometimes pep8 has flip-flopped on an issue or is directly contradictory with itself so it's impossible to follow to a T). this particular part of pep8 is relatively new (2017) and so it's not surprising that pycodestyle has nothing for it.
additionally it's tricky to get correct, in your example
print(1, 2,)it's hard to know whether this is a tuple or function call (sincepycodestyledoes not access the parse tree for performance reasons).you might be interested in some tools which are built around handling these such as add-trailing-comma or black -- both of which are probably better suited to handle this than pycodestyle is
lfiedler commentedon Feb 24, 2021
Thanks for the reply and also for the hints towards the plugin. I'll have a look.
Ironically, I was stumbling over this while using flake8, which, I am assuming, uses pycodestyle, in conjunction with black (which produces these kind of lines under certain circumstances, at least for the version I am using. But that does not belong here.).
lfiedler commentedon Feb 24, 2021
I am not sure I understand your remark about
print(1, 2,): Even if this was a tuple, i.e.(1, 2,)this shouldn't be allowed.asottile commentedon Feb 24, 2021
consider
print(1,)lfiedler commentedon Feb 24, 2021
I see, thanks.