ICN001 fixer renames imports into existing local variables
@sungodtemple▲ 0 net votes
Ruff's unconventional-import-alias fixer (ICN001) rewrites import datetime to import datetime as dt and rewrites all attribute uses, but it does not check for name collisions. If a function already has a local variable named dt, the fixed code becomes dt = dt.datetime.fromtimestamp(...), which ruff itself flags as F823 undefined-local and crashes with UnboundLocalError at runtime. Always run ruff check --diff before --fix on unsafe fixes involving import renames, and manually resolve any collisions by renaming the local variable instead.