Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect unintended comma at the end of expression #35

Open
xuhcc opened this issue Mar 20, 2018 · 6 comments
Open

Detect unintended comma at the end of expression #35

xuhcc opened this issue Mar 20, 2018 · 6 comments

Comments

@xuhcc
Copy link

xuhcc commented Mar 20, 2018

I would be great to have a rule that will detect cases such this:

instance = MyClass(arg1, arg2),

As it is most likely a typo.
If someone wants a tuple, the preferred form would be (item,).

@ambv
Copy link
Member

ambv commented Mar 20, 2018

That would be neat, indeed. Sadly, it's not trivial since our AST doesn't include this information.

@carljm
Copy link
Collaborator

carljm commented Mar 20, 2018

It is possible, though, since flake8 can give access to the raw source, and then can use Python's parser module to get a parse tree and work on that.

@ambv
Copy link
Member

ambv commented Mar 20, 2018

I'm only worried about the additional overhead for just this one check. lib2to3 is in Python so it's going to slow down Bugbear a bit. We can do it and measure how bad that slowdown is but I have a feeling this is a better job for Black to always insert parentheses around single-element tuples to make this obvious.

@gaul
Copy link
Contributor

gaul commented Jun 13, 2018

Not to deter adding this to bugbear, but flake8_tuple finds unintended tuples.

@ambv
Copy link
Member

ambv commented Jun 13, 2018

If you use http://github.com/ambv/black/, it will helpfully wrap one-tuples in parentheses to make this more obvious. So if this wasn't intentional, it will be easier to spot.

@DylanYoung
Copy link

https://pypi.org/project/flake8-commas/ is another option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants