PyCQA / flake8-bugbear

A plugin for Flake8 finding likely bugs and design problems in your program. Contains warnings that don't belong in pyflakes and pycodestyle.
MIT License
1.06k stars 104 forks source link

Detect inline implicit string concatenation #435

Closed r-downing closed 8 months ago

r-downing commented 10 months ago

As specified here https://github.com/PyCQA/flake8-bugbear/issues/156 - this adds a check for inline implicit string concatenation as a new error B036

E.g.

["a", "b" "c"]

becomes

["a", "bc"]

This grabs the segment of the original source and parses it with libcst to see if it's a ConcatenatedString. Had to modify some unittests that manually fed in the AST to also feed in the source lines.

cooperlees commented 9 months ago

My only worry here is libcst is a big depedency to add ... We been light on (and could prob remove attrs with dataclasses these days - but I forget what we use) dependencies on purpose and wanted to be a pure python project for runtime simplicity. libcst is compiled but the right library for this job none the less.

I'd like to see how other contributors + maintainers feel about bringing this dependency in. It brings in many benefits, but now could slow our move to new Python runtimes and brings in the potential for people having wheel install issues + build the extension etc. etc.

JelleZijlstra commented 9 months ago

I agree with your intuition that it's better to keep flake8-bugbear pure Python. It's good to minimize dependencies.

We could reconsider if there are more lints that we want to add but that are only achievable with libcst.

cooperlees commented 8 months ago

Is there a feasible pure python way to implement these checks? If not, I think we should close this PR. I thank you for the efforts tho. Jelle and I (plus other maintainers) bear the pain of black and other projects having compiled dependencies. They lead to a lot of Issues opened. As it's really just me and Jelle here, I'd like to avoid that overhead.

I wonder if someone has started a dedicated libcst based flake8-plugin so people can choose a compiled plugin if they want. If so, maybe the check can go there.