From 97e944003bc454232ca2aaa1d5e56c0b7ff5c772 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Mon, 9 Oct 2023 14:50:51 -0400 Subject: [PATCH] Add `sqlalchemy` methods to boolean-trap exclusion list (#7874) Closes https://github.com/astral-sh/ruff/issues/7869. --- .../resources/test/fixtures/flake8_boolean_trap/FBT.py | 2 ++ .../ruff_linter/src/rules/flake8_boolean_trap/helpers.rs | 4 ++++ ..._rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap | 8 ++++---- ..._rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap | 8 ++++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py b/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py index eba1a03097ddf..88e5468692e10 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py +++ b/crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py @@ -70,6 +70,8 @@ def used(do): foo.is_(True) bar.is_not(False) next(iter([]), False) +sa.func.coalesce(tbl.c.valid, False) + class Registry: def __init__(self) -> None: diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs index 8ff583d7fbd78..58764a783a7fa 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs @@ -12,6 +12,7 @@ pub(super) fn is_allowed_func_call(name: &str) -> bool { | "assertNotEquals" | "bool" | "bytes" + // | "coalesce" | "count" | "failIfEqual" | "failUnlessEqual" @@ -22,12 +23,15 @@ pub(super) fn is_allowed_func_call(name: &str) -> bool { | "getboolean" | "getfloat" | "getint" + | "ifnull" | "index" | "insert" | "int" | "is_" | "is_not" + | "isnull" | "next" + | "nvl" | "param" | "pop" | "remove" diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap b/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap index b1f894ec5c32a..fe9adc83fc21f 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap @@ -81,12 +81,12 @@ FBT.py:19:5: FBT001 Boolean-typed positional argument in function definition 21 | kwonly_nonvalued_nohint, | -FBT.py:87:19: FBT001 Boolean-typed positional argument in function definition +FBT.py:89:19: FBT001 Boolean-typed positional argument in function definition | -86 | # FBT001: Boolean positional arg in function definition -87 | def foo(self, value: bool) -> None: +88 | # FBT001: Boolean positional arg in function definition +89 | def foo(self, value: bool) -> None: | ^^^^^ FBT001 -88 | pass +90 | pass | diff --git a/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap b/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap index d2b902114550b..3e59e30e7d775 100644 --- a/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap +++ b/crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap @@ -38,4 +38,12 @@ FBT.py:69:38: FBT003 Boolean positional value in function call 71 | bar.is_not(False) | +FBT.py:73:31: FBT003 Boolean positional value in function call + | +71 | bar.is_not(False) +72 | next(iter([]), False) +73 | sa.func.coalesce(tbl.c.valid, False) + | ^^^^^ FBT003 + | +