You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Idea for a rule, PyCharm highlighting it, but don't see anything in ruff
file test.py:
# Copyright (c) 2021-2023 Mr XXX <e@ma.il>
"""The docs."""
class MyError(Exception):
"""The exception."""
def func() -> str:
"""Something.
Raises:
MyError: desc.
"""
raise MyError
try:
some_var = func()
except MyError as exception:
if hasattr(exception, "message"):
some_var = "something"
# some_var is not defined in else case
print(some_var) # noqa: T201
execution and ruff check:
$ python3 test.py
Traceback (most recent call last):
File "/.../test.py", line 26, in <module>
print(some_var) # noqa: T201
^^^^^^^^
NameError: name 'some_var' is not defined
$ ruff check --preview --isolated --select ALL test.py
...
All checks passed!
version: ruff 0.6.4
The text was updated successfully, but these errors were encountered:
Correctly modelling try-except is surprisingly hard. @AlexWaygood is currently implementing just that (see #13338) for red knot, our new static analysis backend that eventually will power ruff. However, it will take us a while until we get there.
If you're open to using typed Python, consider using pyright or mypy (until we release red knot ;)). They both should be able to catch this kind of error.
Hi,
Idea for a rule, PyCharm highlighting it, but don't see anything in ruff
file
test.py
:execution and ruff check:
version: ruff 0.6.4
The text was updated successfully, but these errors were encountered: