ruff
ruff copied to clipboard
New rule request: Local variable might be referenced before assignment
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
Makes sense. It's not trivial to fix because it requires supporting full branch analysis, but it would be good to catch of course.
Yeah, seems really complicated, as does all this linter magic haha
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.