# ruff TC005: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: ruff ruff 0.17.1
- Rule: TC005 (tool labels the fix: unknown, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): real, severity high. The fix removes the `if TYPE_CHECKING:` guard but leaves a `pass` statement, changing the code from a no-op (when TYPE_CHECKING is undefined) to an unconditional `pass`. This alters runtime behavior by eliminating the NameError that occurred when evaluating the undefined `TYPE_CHECKING` name, which is a silent change in program semantics for plausible code that relies on the guard to avoid runtime errors.
- Program: minimized from 8 to 4 lines

## Reproducer

```python
def gen():
    if TYPE_CHECKING:
        pass
it = gen()
```

## Commands

```sh
python3 prog.py
ruff check --preview --isolated --select TC005 --fix prog.py
python3 prog.py
```

## Observed

```
exit 1 → 0
stderr before: NameError: name 'TYPE_CHECKING' is not defined
stderr after: (none)
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:29:48.546347841 -0400
+++ fixed.py	2026-10-22 13:29:50.584381923 -0400
@@ -1,4 +1,3 @@
 def gen():
-    if TYPE_CHECKING:
-        pass
+    pass
 it = gen()
```

## Why the rewrite is not equivalent (model draft, verify before use)

The original function contains a conditional that references `TYPE_CHECKING`, which raises a `NameError` when executed because the variable is undefined; this error prevents assignment to `it`. After rewriting, the conditional is removed and replaced with unconditional `pass`, so calling `gen()` succeeds without error and assigns `None` to `it`. Thus, the fix changes behavior by eliminating a runtime exception that was present in the original code.

## Upstream search

Queries: "TC005 fix", "ruff TC005 conditional block removal", "ruff TYPE_CHECKING guard elimination", "ruff unused import cleanup"

- duplicate: https://github.com/astral-sh/ruff/issues/28868
  same TC005 empty-type-checking-block fix removing an if TYPE_CHECKING: pass block and causing a NameError
- related: https://github.com/astral-sh/ruff/issues/15681
  same TC00x family but about false positives with manual TYPE_CHECKING and __future__.annotations
- related: https://github.com/astral-sh/ruff/issues/13929
  detect empty conditional statements after import removal, similar empty-block problem but different trigger

<details><summary>All hits</summary>

- [github, open] TC004 runtime-import-in-type-checking-block fixer causes follow up: TC005 empty-type-checking-block + F401 unused-import + I001 unsorted-imports — https://github.com/astral-sh/ruff/issues/28868
- [github, closed] unused-function-argument not silenced by prefixed underscore if variable name is "次" — https://github.com/astral-sh/ruff/issues/28721
- [github, closed] Ruff Server errors when using a VSCode interactive session — https://github.com/astral-sh/ruff/issues/11851
- [github, closed] TC003/TC002/TC001 False positive on manual `TYPE_CHECKING` with `__future__.annotations` — https://github.com/astral-sh/ruff/issues/15681
- [github, closed] `TC006` in `0.8.1` is too broad — https://github.com/astral-sh/ruff/issues/14676
- [github, closed] Implement flake8-type-checking — https://github.com/astral-sh/ruff/issues/1785
- [tavily] Can "Unknown rule selector" be a warning, rather than an error? · Issue #5159 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/5159
- [github, open] Allow removing unused imports from standard library only — https://github.com/astral-sh/ruff/issues/6601
- [github, open] Implement Pylint — https://github.com/astral-sh/ruff/issues/970
- [github, open] Support baselines, i.e., ignore existing errors for incremental adoption — https://github.com/astral-sh/ruff/issues/1149
- [github, closed] `RUF102` fix causes syntax error by not handling text following directive — https://github.com/astral-sh/ruff/issues/23349
- [github, closed] Unnecessary `crate::` prefixes in `crates/ruff_python_ast/generated.rs` — https://github.com/astral-sh/ruff/issues/18651
- [github, closed] [Infinite loop] Failed to Converge After 100 Iterations When Fixing Imports (e.g., I001, F401, F811) — https://github.com/astral-sh/ruff/issues/15182
- [tavily] Ruff does not clean up unused import if it has same name like object attribute · Issue #12775 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/12775
- [tavily] [feature] remove unused imports · Issue #4195 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/4195
- [tavily] Add fix to re-export unused first-party imports in `__init__.py` files · Issue #10391 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/10391
- [tavily] Detect empty conditional statements · Issue #13929 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/13929

</details>
