Skip to content

Commit 97e9440

Browse files
Add sqlalchemy methods to boolean-trap exclusion list (#7874)
Closes #7869.
1 parent 016e162 commit 97e9440

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_boolean_trap/FBT.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ def used(do):
7070
foo.is_(True)
7171
bar.is_not(False)
7272
next(iter([]), False)
73+
sa.func.coalesce(tbl.c.valid, False)
74+
7375

7476
class Registry:
7577
def __init__(self) -> None:

crates/ruff_linter/src/rules/flake8_boolean_trap/helpers.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(super) fn is_allowed_func_call(name: &str) -> bool {
1212
| "assertNotEquals"
1313
| "bool"
1414
| "bytes"
15+
// | "coalesce"
1516
| "count"
1617
| "failIfEqual"
1718
| "failUnlessEqual"
@@ -22,12 +23,15 @@ pub(super) fn is_allowed_func_call(name: &str) -> bool {
2223
| "getboolean"
2324
| "getfloat"
2425
| "getint"
26+
| "ifnull"
2527
| "index"
2628
| "insert"
2729
| "int"
2830
| "is_"
2931
| "is_not"
32+
| "isnull"
3033
| "next"
34+
| "nvl"
3135
| "param"
3236
| "pop"
3337
| "remove"

crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT001_FBT.py.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,12 @@ FBT.py:19:5: FBT001 Boolean-typed positional argument in function definition
8181
21 | kwonly_nonvalued_nohint,
8282
|
8383

84-
FBT.py:87:19: FBT001 Boolean-typed positional argument in function definition
84+
FBT.py:89:19: FBT001 Boolean-typed positional argument in function definition
8585
|
86-
86 | # FBT001: Boolean positional arg in function definition
87-
87 | def foo(self, value: bool) -> None:
86+
88 | # FBT001: Boolean positional arg in function definition
87+
89 | def foo(self, value: bool) -> None:
8888
| ^^^^^ FBT001
89-
88 | pass
89+
90 | pass
9090
|
9191

9292

crates/ruff_linter/src/rules/flake8_boolean_trap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__FBT003_FBT.py.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,12 @@ FBT.py:69:38: FBT003 Boolean positional value in function call
3838
71 | bar.is_not(False)
3939
|
4040

41+
FBT.py:73:31: FBT003 Boolean positional value in function call
42+
|
43+
71 | bar.is_not(False)
44+
72 | next(iter([]), False)
45+
73 | sa.func.coalesce(tbl.c.valid, False)
46+
| ^^^^^ FBT003
47+
|
48+
4149

0 commit comments

Comments
 (0)