-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working