ruff: FBT003: False positive with positional-only parameters
FBT003 is triggered even if only positional arguments are allowed.
Toy example below - I stumbled upon it with a Pandas decorator:
with pd.option_context("mode.use_inf_as_na", True):
....
Example
def foo(*args):
pass
def foo2(a = False, *args):
pass
foo(False) # Should not warn
# foo2(True), # Warns as expected
foo2("a", False) # Should not warn
Errors
fbt003.py:8:5: FBT003 Boolean positional value in function call
fbt003.py:10:11: FBT003 Boolean positional value in function call
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 6
- Comments: 16 (9 by maintainers)
Commits related to this issue
- Add some exceptions for FBT003 (#3247) Hardcode a few exceptions for FBT003 (passing a boolean constant to a function): - bool (builtin) - set_blocking (from 'os' in the stdlib) - set_enabled ... — committed to allisonkarlitskaya/ruff by allisonkarlitskaya 3 years ago
- Add some exceptions for FBT003 (#3247) (#4867) — committed to astral-sh/ruff by allisonkarlitskaya 3 years ago
- Add some exceptions for FBT003 (#3247) (#4867) — committed to astral-sh/ruff by allisonkarlitskaya 3 years ago
- Apply flake8-boolean-trap rule Some false-positives: https://github.com/astral-sh/ruff/issues/3247 https://github.com/astral-sh/ruff/issues/9497 — committed to Toufool/AutoSplit by Avasam 3 years ago
- Apply flake8-boolean-trap rule Some false-positives: https://github.com/astral-sh/ruff/issues/3247 https://github.com/astral-sh/ruff/issues/9497 — committed to Toufool/AutoSplit by Avasam 3 years ago
- Apply flake8-boolean-trap rule Some false-positives: https://github.com/astral-sh/ruff/issues/3247 https://github.com/astral-sh/ruff/issues/9497 — committed to Toufool/AutoSplit by Avasam 3 years ago
Just wanted to mention, there are cases in pytest fixtures where this comes up too. For example:
In this case, the FBT rule says this
throw_errneeds to be a kwarg. Which is a bit weird as tests are never really going to be called by anyone other than pytest ?FWIW the same issue is for all the various
set* methods you can find in PySide / PyQt, for example QTableView.setSortingEnabled or QHeaderView.setSortIndicatorShown (or many others).If you try to call them setting the flag with a keyword, you get a runtime error, like
Okay. Let me see if I can even get the thing to build, first 😉
I guess the rule I’d like in the list is “instance method named
set_*with single positional boolean argument” and “(non-class) function namedset_*with two arguments, second of which is a positional-only boolean”.@charliermarsh was that “… so I’ll take a look at this soon” or was that “… so, patches welcome”? 😃 I never wrote rust before, but no time like the present…
A related case is this one:
The error message is correct in this case, but I’d argue that the author is doing this intentionally.