mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
Fix F811 false positive with match (#4161)
This commit is contained in:
parent
a32617911a
commit
8c97e7922b
4 changed files with 22 additions and 0 deletions
13
crates/ruff/resources/test/fixtures/pyflakes/F811_22.py
vendored
Normal file
13
crates/ruff/resources/test/fixtures/pyflakes/F811_22.py
vendored
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
def redef(value):
|
||||||
|
match value:
|
||||||
|
case True:
|
||||||
|
|
||||||
|
def fun(x, y):
|
||||||
|
return x
|
||||||
|
|
||||||
|
case False:
|
||||||
|
|
||||||
|
def fun(x, y):
|
||||||
|
return y
|
||||||
|
|
||||||
|
return fun
|
|
@ -96,6 +96,7 @@ mod tests {
|
||||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_19.py"); "F811_19")]
|
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_19.py"); "F811_19")]
|
||||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_20.py"); "F811_20")]
|
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_20.py"); "F811_20")]
|
||||||
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_21.py"); "F811_21")]
|
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_21.py"); "F811_21")]
|
||||||
|
#[test_case(Rule::RedefinedWhileUnused, Path::new("F811_22.py"); "F811_22")]
|
||||||
#[test_case(Rule::UndefinedName, Path::new("F821_0.py"); "F821_0")]
|
#[test_case(Rule::UndefinedName, Path::new("F821_0.py"); "F821_0")]
|
||||||
#[test_case(Rule::UndefinedName, Path::new("F821_1.py"); "F821_1")]
|
#[test_case(Rule::UndefinedName, Path::new("F821_1.py"); "F821_1")]
|
||||||
#[test_case(Rule::UndefinedName, Path::new("F821_2.py"); "F821_2")]
|
#[test_case(Rule::UndefinedName, Path::new("F821_2.py"); "F821_2")]
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
---
|
||||||
|
source: crates/ruff/src/rules/pyflakes/mod.rs
|
||||||
|
---
|
||||||
|
|
|
@ -71,6 +71,10 @@ fn alternatives(stmt: RefEquality<Stmt>) -> Vec<Vec<RefEquality<Stmt>>> {
|
||||||
body.iter().map(RefEquality).collect()
|
body.iter().map(RefEquality).collect()
|
||||||
}))
|
}))
|
||||||
.collect(),
|
.collect(),
|
||||||
|
StmtKind::Match { cases, .. } => cases
|
||||||
|
.iter()
|
||||||
|
.map(|case| case.body.iter().map(RefEquality).collect())
|
||||||
|
.collect(),
|
||||||
_ => vec![],
|
_ => vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue