-
Notifications
You must be signed in to change notification settings - Fork 914
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix FBT001 false negative with unions and optional (#7501)
## Summary - Close #7487 In the spirit of `flake8-boolean-trap`, any positional argument that can accept a boolean should raise `FBT001`. Raise `FBT001` for all annotations that accept booleans (e.g. `Optional[bool]`, `Union[int, bool]`). ## Test Plan Add a fixture, with an annotation using `|`, `Optional`, and `Union`, and containing a boolean.
- Loading branch information
1 parent
5f78580
commit 776eb87
Showing
4 changed files
with
207 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
...rap/snapshots/ruff_linter__rules__flake8_boolean_trap__tests__preview__FBT001_FBT.py.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_boolean_trap/mod.rs | ||
--- | ||
FBT.py:4:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
2 | posonly_nohint, | ||
3 | posonly_nonboolhint: int, | ||
4 | posonly_boolhint: bool, | ||
| ^^^^^^^^^^^^^^^^ FBT001 | ||
5 | posonly_boolstrhint: "bool", | ||
6 | /, | ||
| | ||
|
||
FBT.py:5:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
3 | posonly_nonboolhint: int, | ||
4 | posonly_boolhint: bool, | ||
5 | posonly_boolstrhint: "bool", | ||
| ^^^^^^^^^^^^^^^^^^^ FBT001 | ||
6 | /, | ||
7 | offset, | ||
| | ||
|
||
FBT.py:10:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
8 | posorkw_nonvalued_nohint, | ||
9 | posorkw_nonvalued_nonboolhint: int, | ||
10 | posorkw_nonvalued_boolhint: bool, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 | ||
11 | posorkw_nonvalued_boolstrhint: "bool", | ||
12 | posorkw_boolvalued_nohint=True, | ||
| | ||
|
||
FBT.py:11:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
9 | posorkw_nonvalued_nonboolhint: int, | ||
10 | posorkw_nonvalued_boolhint: bool, | ||
11 | posorkw_nonvalued_boolstrhint: "bool", | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 | ||
12 | posorkw_boolvalued_nohint=True, | ||
13 | posorkw_boolvalued_nonboolhint: int = True, | ||
| | ||
|
||
FBT.py:14:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
12 | posorkw_boolvalued_nohint=True, | ||
13 | posorkw_boolvalued_nonboolhint: int = True, | ||
14 | posorkw_boolvalued_boolhint: bool = True, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 | ||
15 | posorkw_boolvalued_boolstrhint: "bool" = True, | ||
16 | posorkw_nonboolvalued_nohint=1, | ||
| | ||
|
||
FBT.py:15:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
13 | posorkw_boolvalued_nonboolhint: int = True, | ||
14 | posorkw_boolvalued_boolhint: bool = True, | ||
15 | posorkw_boolvalued_boolstrhint: "bool" = True, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 | ||
16 | posorkw_nonboolvalued_nohint=1, | ||
17 | posorkw_nonboolvalued_nonboolhint: int = 2, | ||
| | ||
|
||
FBT.py:18:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
16 | posorkw_nonboolvalued_nohint=1, | ||
17 | posorkw_nonboolvalued_nonboolhint: int = 2, | ||
18 | posorkw_nonboolvalued_boolhint: bool = 3, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 | ||
19 | posorkw_nonboolvalued_boolstrhint: "bool" = 4, | ||
20 | *, | ||
| | ||
|
||
FBT.py:19:5: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
17 | posorkw_nonboolvalued_nonboolhint: int = 2, | ||
18 | posorkw_nonboolvalued_boolhint: bool = 3, | ||
19 | posorkw_nonboolvalued_boolstrhint: "bool" = 4, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FBT001 | ||
20 | *, | ||
21 | kwonly_nonvalued_nohint, | ||
| | ||
|
||
FBT.py:89:19: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
88 | # FBT001: Boolean positional arg in function definition | ||
89 | def foo(self, value: bool) -> None: | ||
| ^^^^^ FBT001 | ||
90 | pass | ||
| | ||
|
||
FBT.py:99:10: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
99 | def func(x: Union[list, Optional[int | str | float | bool]]): | ||
| ^ FBT001 | ||
100 | pass | ||
| | ||
|
||
FBT.py:103:10: FBT001 Boolean-typed positional argument in function definition | ||
| | ||
103 | def func(x: bool | str): | ||
| ^ FBT001 | ||
104 | pass | ||
| | ||
|
||
|