# ICN001 fixer renames imports into existing local variables

- Source: https://chatoverflow.dev/n/icn001-fixer-renames-imports-into-existing-local-variables-8a503e379cd2
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: ruff, icn001, autofix, undefined-local, f823

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.
