Skip to content

Commit

Permalink
Nits
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 16, 2024
1 parent a9cc844 commit 8d98cb9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
21 changes: 11 additions & 10 deletions crates/ruff_linter/src/rules/ruff/rules/redundant_bool_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,16 @@ impl Violation for RedundantBoolLiteral {
if self.seen_others {
"`Literal[True, False, ...]` can be replaced with `Literal[...] | bool`".to_string()
} else {
"`Literal[True, False]` can be replaced with a bare `bool`".to_string()
"`Literal[True, False]` can be replaced with `bool`".to_string()
}
}

fn fix_title(&self) -> Option<String> {
let title = if self.seen_others {
"Replace with `Literal[...] | bool`"
Some(if self.seen_others {
"Replace with `Literal[...] | bool`".to_string()
} else {
"Replace with `bool`"
};
Some(title.to_string())
"Replace with `bool`".to_string()
})
}
}

Expand Down Expand Up @@ -117,10 +116,12 @@ pub(crate) fn redundant_bool_literal<'a>(checker: &mut Checker, literal_expr: &'
// Provide a [`Fix`] when the complete `Literal` can be replaced. Applying the fix
// can leave an unused import to be fixed by the `unused-import` rule.
if !seen_others {
diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement(
"bool".to_string(),
literal_expr.range(),
)));
if checker.semantic().has_builtin_binding("bool") {
diagnostic.set_fix(Fix::unsafe_edit(Edit::range_replacement(
"bool".to_string(),
literal_expr.range(),
)));
}
}

checker.diagnostics.push(diagnostic);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF038.py:4:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.py:4:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
4 | def func1(arg1: Literal[True, False]):
| ^^^^^^^^^^^^^^^^^^^^ RUF038
Expand All @@ -19,7 +19,7 @@ RUF038.py:4:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `b
6 6 |
7 7 |

RUF038.py:8:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.py:8:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
8 | def func2(arg1: Literal[True, False, True]):
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ RUF038
Expand All @@ -37,7 +37,7 @@ RUF038.py:8:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `b
10 10 |
11 11 |

RUF038.py:12:16: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.py:12:16: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
12 | def func3() -> Literal[True, False]:
| ^^^^^^^^^^^^^^^^^^^^ RUF038
Expand All @@ -55,7 +55,7 @@ RUF038.py:12:16: RUF038 [*] `Literal[True, False]` can be replaced with a bare `
14 14 |
15 15 |

RUF038.py:16:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.py:16:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
16 | def func4(arg1: Literal[True, False] | bool):
| ^^^^^^^^^^^^^^^^^^^^ RUF038
Expand All @@ -73,7 +73,7 @@ RUF038.py:16:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `
18 18 |
19 19 |

RUF038.py:20:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.py:20:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
20 | def func5(arg1: Literal[False, True]):
| ^^^^^^^^^^^^^^^^^^^^ RUF038
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/ruff/mod.rs
---
RUF038.pyi:4:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.pyi:4:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
4 | def func1(arg1: Literal[True, False]): ...
| ^^^^^^^^^^^^^^^^^^^^ RUF038
Expand All @@ -20,7 +20,7 @@ RUF038.pyi:4:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `
6 6 | def func2(arg1: Literal[True, False, True]): ...
7 7 |

RUF038.pyi:6:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.pyi:6:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
4 | def func1(arg1: Literal[True, False]): ...
5 |
Expand All @@ -41,7 +41,7 @@ RUF038.pyi:6:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `
8 8 | def func3() -> Literal[True, False]: ...
9 9 |

RUF038.pyi:8:16: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.pyi:8:16: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
6 | def func2(arg1: Literal[True, False, True]): ...
7 |
Expand All @@ -62,7 +62,7 @@ RUF038.pyi:8:16: RUF038 [*] `Literal[True, False]` can be replaced with a bare `
10 10 | def func4(arg1: Literal[True, False] | bool): ...
11 11 |

RUF038.pyi:10:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.pyi:10:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
8 | def func3() -> Literal[True, False]: ...
9 |
Expand All @@ -83,7 +83,7 @@ RUF038.pyi:10:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare
12 12 | def func5(arg1: Literal[False, True]): ...
13 13 |

RUF038.pyi:12:17: RUF038 [*] `Literal[True, False]` can be replaced with a bare `bool`
RUF038.pyi:12:17: RUF038 [*] `Literal[True, False]` can be replaced with `bool`
|
10 | def func4(arg1: Literal[True, False] | bool): ...
11 |
Expand Down

0 comments on commit 8d98cb9

Please sign in to comment.