From dc223fd3cab5b7cec1fb3334ba3be8a98b608bfa Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Mon, 5 Jun 2023 18:44:49 +0200 Subject: [PATCH] Add some exceptions for FBT003 (#3247) (#4867) --- .../resources/test/fixtures/flake8_boolean_trap/FBT.py | 4 ++++ crates/ruff/src/rules/flake8_boolean_trap/helpers.rs | 3 +++ ..._rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap | 8 ++++---- ..._rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap | 8 ++++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/ruff/resources/test/fixtures/flake8_boolean_trap/FBT.py b/crates/ruff/resources/test/fixtures/flake8_boolean_trap/FBT.py index eacf248284..581668e932 100644 --- a/crates/ruff/resources/test/fixtures/flake8_boolean_trap/FBT.py +++ b/crates/ruff/resources/test/fixtures/flake8_boolean_trap/FBT.py @@ -57,12 +57,16 @@ dict.fromkeys(("world",), True) {}.deploy(True, False) getattr(someobj, attrname, False) mylist.index(True) +bool(False) int(True) str(int(False)) cfg.get("hello", True) cfg.getint("hello", True) cfg.getfloat("hello", True) cfg.getboolean("hello", True) +os.set_blocking(0, False) +g_action.set_enabled(True) +settings.set_enable_developer_extras(True) class Registry: diff --git a/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs b/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs index 963fd62b89..2c397470b7 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs +++ b/crates/ruff/src/rules/flake8_boolean_trap/helpers.rs @@ -10,6 +10,7 @@ pub(super) const FUNC_CALL_NAME_ALLOWLIST: &[&str] = &[ "assertEquals", "assertNotEqual", "assertNotEquals", + "bool", "bytes", "count", "failIfEqual", @@ -27,6 +28,8 @@ pub(super) const FUNC_CALL_NAME_ALLOWLIST: &[&str] = &[ "param", "pop", "remove", + "set_blocking", + "set_enabled", "setattr", "__setattr__", "setdefault", diff --git a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap index c940e93364..4f54d13871 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap +++ b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap @@ -81,12 +81,12 @@ FBT.py:19:5: FBT001 Boolean positional arg in function definition 23 | kwonly_nonvalued_nohint, | -FBT.py:81:19: FBT001 Boolean positional arg in function definition +FBT.py:85:19: FBT001 Boolean positional arg in function definition | -81 | # FBT001: Boolean positional arg in function definition -82 | def foo(self, value: bool) -> None: +85 | # FBT001: Boolean positional arg in function definition +86 | def foo(self, value: bool) -> None: | ^^^^^^^^^^^ FBT001 -83 | pass +87 | pass | diff --git a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap index 43058488d3..1aeb008182 100644 --- a/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap +++ b/crates/ruff/src/rules/flake8_boolean_trap/snapshots/ruff__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap @@ -28,4 +28,12 @@ FBT.py:57:17: FBT003 Boolean positional value in function call 61 | mylist.index(True) | +FBT.py:69:38: FBT003 Boolean positional value in function call + | +69 | os.set_blocking(0, False) +70 | g_action.set_enabled(True) +71 | settings.set_enable_developer_extras(True) + | ^^^^ FBT003 + | +