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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

B028 suggestion is wrong when double quotes are required

mlegner opened this issue · comments

The !r flag surrounds strings by single quotes. In some cases, for example when constructing SQL commands, single quotes are not valid and the suggestion leads to incorrect results.

One solution would be to only trigger B028 when strings are surrounded by single quotes.

B028 is also wrong when the variable being formatted is not a string -- !r doesn't systematically add quotes.

Could B028 gets moved to the "opinionated warnings" section?

Only triggering on single quotes is pretty reasonable, and a decent way to get around many false positives, though requiring quotes is reasonably uncommon so if moved to opinionated it might be worth keeping. Could also do fancy stuff like disable the check if common sql libraries are imported.

@brutasse See also #329

But yeah I think this will end up in opinionated warnings.

@Zac-HD

Yeah, let's move to the disabled-by-default checks. Apologies for the churn @brutasse!