Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional test cases for F823 #6036

Merged
merged 1 commit into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions crates/ruff/resources/test/fixtures/pyflakes/F823.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,27 @@ class Class:
def f(self):
print(my_var)
my_var = 1


import sys


def main():
print(sys.argv)

try:
3 / 0
except ZeroDivisionError:
import sys

sys.exit(1)


import sys


def main():
print(sys.argv)

for sys in range(5):
pass
2 changes: 1 addition & 1 deletion crates/ruff/src/rules/pyflakes/rules/undefined_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use crate::checkers::ast::Checker;
/// ```
#[violation]
pub struct UndefinedLocal {
pub name: String,
name: String,
}

impl Violation for UndefinedLocal {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,22 @@ F823.py:40:15: F823 Local variable `my_var` referenced before assignment
41 | my_var = 1
|

F823.py:48:11: F823 Local variable `sys` referenced before assignment
|
47 | def main():
48 | print(sys.argv)
| ^^^ F823
49 |
50 | try:
|

F823.py:62:11: F823 Local variable `sys` referenced before assignment
|
61 | def main():
62 | print(sys.argv)
| ^^^ F823
63 |
64 | for sys in range(5):
|


Loading