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
Contrived example, but ruff 0.0.271 flags the below import inside of fn with F401 (unused import) and auto-deletes it, but this results in a runtime error when you execute the code, because the first argument to cast doesn't get a deferred annotation like a function parameter:
from __future__ import annotations
from typing import TYPE_CHECKING, cast
if TYPE_CHECKING:
from threading import Thread
def fn(thread: Thread):
from threading import Thread # Flagged as F401
casted_thread = cast(Thread, thread)
return casted_thread
print(fn(1))
You can work around it by quoting the cast argument, but still a bug.
The text was updated successfully, but these errors were encountered:
smackesey
changed the title
F401 false positive for imports inside functions
[bug] F401 false positive for imports inside functions
Jun 7, 2023
Contrived example, but ruff 0.0.271 flags the below import inside of
fn
with F401 (unused import) and auto-deletes it, but this results in a runtime error when you execute the code, because the first argument tocast
doesn't get a deferred annotation like a function parameter:You can work around it by quoting the cast argument, but still a bug.
The text was updated successfully, but these errors were encountered: