mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[flake8-simplify
] Do not emit diagnostics for expressions inside string type annotations (SIM222
, SIM223
) (#15405)
## Summary Resolves #7127. ## Test Plan `cargo nextest run` and `cargo insta test`.
This commit is contained in:
parent
7ddf59be5f
commit
556116ee76
4 changed files with 18 additions and 0 deletions
|
@ -193,3 +193,7 @@ for x in (*a, *b) or [None]:
|
|||
|
||||
for x in {**a, **b} or [None]:
|
||||
pass
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/7127
|
||||
def f(a: "'b' or 'c'"): ...
|
||||
|
|
|
@ -153,3 +153,7 @@ print(f"{a}{b}" and "bar")
|
|||
print(f"{a}{''}" and "bar")
|
||||
print(f"{''}{''}" and "bar")
|
||||
print(f"{1}{''}" and "bar")
|
||||
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/7127
|
||||
def f(a: "'' and 'b'"): ...
|
||||
|
|
|
@ -833,6 +833,10 @@ fn is_short_circuit(
|
|||
|
||||
/// SIM222
|
||||
pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) {
|
||||
if checker.semantic().in_string_type_definition() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some((edit, remove)) = is_short_circuit(expr, BoolOp::Or, checker) {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
ExprOrTrue {
|
||||
|
@ -848,6 +852,10 @@ pub(crate) fn expr_or_true(checker: &mut Checker, expr: &Expr) {
|
|||
|
||||
/// SIM223
|
||||
pub(crate) fn expr_and_false(checker: &mut Checker, expr: &Expr) {
|
||||
if checker.semantic().in_string_type_definition() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some((edit, remove)) = is_short_circuit(expr, BoolOp::And, checker) {
|
||||
let mut diagnostic = Diagnostic::new(
|
||||
ExprAndFalse {
|
||||
|
|
|
@ -1023,3 +1023,5 @@ SIM223.py:154:7: SIM223 [*] Use `f"{''}{''}"` instead of `f"{''}{''}" and ...`
|
|||
154 |-print(f"{''}{''}" and "bar")
|
||||
154 |+print(f"{''}{''}")
|
||||
155 155 | print(f"{1}{''}" and "bar")
|
||||
156 156 |
|
||||
157 157 |
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue