@@ -7,12 +7,12 @@ use ruff_python_semantic::analyze::visibility;
7
7
8
8
use crate :: Violation ;
9
9
use crate :: checkers:: ast:: Checker ;
10
- use crate :: preview:: is_bool_subtype_of_annotation_enabled;
11
10
use crate :: rules:: flake8_boolean_trap:: helpers:: is_allowed_func_def;
12
11
13
12
/// ## What it does
14
13
/// Checks for the use of boolean positional arguments in function definitions,
15
- /// as determined by the presence of a `bool` type hint.
14
+ /// as determined by the presence of a type hint containing `bool` as an
15
+ /// evident subtype - e.g. `bool`, `bool | int`, `typing.Optional[bool]`, etc.
16
16
///
17
17
/// ## Why is this bad?
18
18
/// Calling a function with boolean positional arguments is confusing as the
@@ -30,9 +30,6 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
30
30
/// Dunder methods that define operators are exempt from this rule, as are
31
31
/// setters and `@override` definitions.
32
32
///
33
- /// In [preview], this rule will also flag annotations that include boolean
34
- /// variants, like `bool | int`.
35
- ///
36
33
/// ## Example
37
34
///
38
35
/// ```python
@@ -96,8 +93,6 @@ use crate::rules::flake8_boolean_trap::helpers::is_allowed_func_def;
96
93
/// ## References
97
94
/// - [Python documentation: Calls](https://docs.python.org/3/reference/expressions.html#calls)
98
95
/// - [_How to Avoid “The Boolean Trap”_ by Adam Johnson](https://adamj.eu/tech/2021/07/10/python-type-hints-how-to-avoid-the-boolean-trap/)
99
- ///
100
- /// [preview]: https://docs.astral.sh/ruff/preview/
101
96
#[ derive( ViolationMetadata ) ]
102
97
pub ( crate ) struct BooleanTypeHintPositionalArgument ;
103
98
@@ -128,14 +123,8 @@ pub(crate) fn boolean_type_hint_positional_argument(
128
123
let Some ( annotation) = parameter. annotation ( ) else {
129
124
continue ;
130
125
} ;
131
- if is_bool_subtype_of_annotation_enabled ( checker. settings ) {
132
- if !match_annotation_to_complex_bool ( annotation, checker. semantic ( ) ) {
133
- continue ;
134
- }
135
- } else {
136
- if !match_annotation_to_literal_bool ( annotation) {
137
- continue ;
138
- }
126
+ if !match_annotation_to_complex_bool ( annotation, checker. semantic ( ) ) {
127
+ continue ;
139
128
}
140
129
141
130
// Allow Boolean type hints in setters.
@@ -161,17 +150,6 @@ pub(crate) fn boolean_type_hint_positional_argument(
161
150
}
162
151
}
163
152
164
- /// Returns `true` if the annotation is a boolean type hint (e.g., `bool`).
165
- fn match_annotation_to_literal_bool ( annotation : & Expr ) -> bool {
166
- match annotation {
167
- // Ex) `True`
168
- Expr :: Name ( name) => & name. id == "bool" ,
169
- // Ex) `"True"`
170
- Expr :: StringLiteral ( ast:: ExprStringLiteral { value, .. } ) => value == "bool" ,
171
- _ => false ,
172
- }
173
- }
174
-
175
153
/// Returns `true` if the annotation is a boolean type hint (e.g., `bool`), or a type hint that
176
154
/// includes boolean as a variant (e.g., `bool | int`).
177
155
fn match_annotation_to_complex_bool ( annotation : & Expr , semantic : & SemanticModel ) -> bool {
0 commit comments