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

New rule request: Local variable might be referenced before assignment #6902

Open
Garrett-R opened this issue Aug 26, 2023 · 5 comments
Open
Labels
bug Something isn't working

Comments

@Garrett-R
Copy link

Garrett-R commented Aug 26, 2023

It would be awesome if Ruff could catch an error (like PyCharm does) for code like this:

def func(x: bool) -> int:
    if x:
        y = 1
    return y
@charliermarsh charliermarsh added the bug Something isn't working label Aug 26, 2023
@charliermarsh
Copy link
Member

Makes sense. It's not trivial to fix because it requires supporting full branch analysis, but it would be good to catch of course.

@Garrett-R
Copy link
Author

Garrett-R commented Aug 26, 2023

Yeah, seems really complicated, as does all this linter magic haha

@inoa-jboliveira
Copy link

At least pycharm and possibly other IDEs static code analysis can catch this bug. I was also hoping to also find this rule in Ruff.
I thought F823 would catch this, but it doesn't.

@clemente0731
Copy link

SAME ISSUE FOR "Local variable might be referenced before assignment"

@clemente0731
Copy link

https://github.com/google/pytype can work well for this @charliermarsh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants