# 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:` block without ensuring `TYPE_CHECKING` is imported from `typing`. The original code crashed with a NameError because `TYPE_CHECKING` was undefined; after the fix, the crash disappears and the function returns `None`. Since the documentation presents the rewrite as a safe removal of dead code but does not mention the required import, the fix changes runtime behavior from an error to silent success in plausible code.
- Program: minimized from 9 to 6 lines

## Reproducer

```python
def f(a=None):
    if a is None:
        a = []
    if TYPE_CHECKING:
        pass
print(f())
```

## Commands

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

## Observed

```
stdout before:

stdout after:
None
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:37.047155587 -0400
+++ fixed.py	2026-10-22 13:29:39.170191076 -0400
@@ -1,6 +1,4 @@
 def f(a=None):
     if a is None:
         a = []
-    if TYPE_CHECKING:
-        pass
 print(f())
```

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

The original function raises a NameError when called because `TYPE_CHECKING` is undefined outside type-checking contexts; this exception prevents execution from reaching the `print` statement. Removing the conditional block eliminates the error, allowing the function to return the default list `[]`, which is then printed. Thus, the rewrite changes behavior by suppressing an exception that altered program flow.

## Upstream search

Queries: "TC005 fix", "TC005 mutable default argument", "ruff TC005 list initialization pattern", "fix removes unused TYPE_CHECKING block"

- related: https://github.com/astral-sh/ruff/issues/28868
  same rule TC005 but different construct (empty block after import removal vs undefined TYPE_CHECKING)
- related: https://github.com/astral-sh/ruff/issues/15681
  same TYPE_CHECKING detection logic but different construct (manual False assignment vs undefined name)
- related: https://github.com/astral-sh/ruff/pull/16669
  same TC005 rule and TYPE_CHECKING block detection logic, but PR changes what counts as a type-checking block
- related: https://github.com/astral-sh/ruff/issues/11368
  same TCH/TC family, autofix deletes else block removing code, similar over-deletion risk
- related: https://github.com/astral-sh/ruff/issues/15526
  same TYPE_CHECKING block context, but about self-assignment to silence unused import
- related: https://github.com/astral-sh/ruff/issues/16176
  same TC003 rule and TYPE_CHECKING = False handling, different construct
- related: https://github.com/astral-sh/ruff/issues/9197
  same TCH rules moving imports into TYPE_CHECKING blocks, but different failure mode

<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
- [tavily] Autofix B006 (mutable-argument-default) · Issue #4693 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/4693
- [tavily] Ignore `mutable-argument-default (B006)` in `.pyi` stubs · Issue #14026 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/14026
- [tavily] B006 doesn’t flag mutable defaults when passed via a named constant · Issue #21142 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/21142
- [tavily] mutable-dataclass-default (RUF008) not detecting mutable_default field · Issue #16539 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/16539
- [tavily] B006 doesn’t detect mutable defaults in tuples, generators, and assignment expressions · Issue #20004 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/20004
- [tavily] `per-file-target-version` override ignored when combined with a broader pattern · Issue #20668 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/20668
- [tavily] Support pattern matching · Issue #282 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/282
- [tavily] Ruff incorrectly ignores Python files included by negated pattern in .gitignore · Issue #8753 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/8753
- [tavily] Consider all `TYPE_CHECKING` symbols for type-checking blocks by MichaReiser · Pull Request #16669 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/pull/16669
- [github, open] F401: Ruff Incorrectly Flags Quoted Class used as Generic Parameter as Unused — https://github.com/astral-sh/ruff/issues/9298
- [github, closed] TCH005 autofix deletes else block, removes functional code. — https://github.com/astral-sh/ruff/issues/11368
- [tavily] Allow Self-Assignment of variable in TYPE_CHECKING block · Issue #15526 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/15526
- [tavily] TC003: Allow `TYPE_CHECKING = False` · Issue #16176 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/16176
- [tavily] Feature Request: Move type-only imports to `TYPE_CHECKING` block · Issue #11447 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/11447
- [tavily] New Rule Proposal: Consolidate imports from the same module unnecessarily split by `TYPE_CHECKING` · Issue #19548 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/19548
- [tavily] [TCH] moving `typing` imports into `TYPE_CHECKING` block does not work as intended · Issue #9197 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/9197
- [tavily] The option lines-after-imports does not work after if block · Issue #10014 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/10014

</details>
