Fix F811 false positive with match (#4161)

This commit is contained in:
Jonathan Plasse 2023-04-30 20:39:45 +02:00 committed by GitHub
parent a32617911a
commit 8c97e7922b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 0 deletions

View 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

View file

@ -96,6 +96,7 @@ mod tests {
#[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_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_1.py"); "F821_1")]
#[test_case(Rule::UndefinedName, Path::new("F821_2.py"); "F821_2")]

View file

@ -0,0 +1,4 @@
---
source: crates/ruff/src/rules/pyflakes/mod.rs
---

View file

@ -71,6 +71,10 @@ fn alternatives(stmt: RefEquality<Stmt>) -> Vec<Vec<RefEquality<Stmt>>> {
body.iter().map(RefEquality).collect()
}))
.collect(),
StmtKind::Match { cases, .. } => cases
.iter()
.map(|case| case.body.iter().map(RefEquality).collect())
.collect(),
_ => vec![],
}
}