# ruff UP038: tool crashes

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: UP038 (tool labels the fix: unknown)
- Oracle: tool-crash
- Judge (Nemotron 3 Ultra, advisory): program-bug, severity low. The linter crashed because rule UP038 was removed from the codebase and cannot be selected, which is a tool availability issue unrelated to the program's syntax error (invalid nonlocal usage). The observed failure stems from the execution environment lacking the rule, not from any rewrite applied to the source code.
- Program: minimized from 8 to 2 lines

## Reproducer

```python
class T:
    def __init__(self): nonlocal counter; counter += 1
```

## Commands

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

## Observed

```
lint crashed: ruff failed
  Cause: Rule `UP038` was removed and cannot be selected.
```

## Diff applied by the fix

```diff

```

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

The original code attempts to use `nonlocal counter` inside `__init__`, which requires `counter` to be defined in an enclosing function scope—there is none, so it raises a SyntaxError before execution. If somehow executed (e.g., via eval or dynamic context), it would modify a variable from an outer function scope. The "fix" does nothing (no diff), but labels it unsafe because the construct is invalid: removing or ignoring the rule doesn't make the code valid. Since the code is syntactically incorrect, any behavior—including crashing during linting—is expected, and there is no semantics-preserving transformation possible without adding an enclosing scope or changing `nonlocal` to `global` or a direct assignment, which would alter meaning. Thus, no safe rewrite exists that preserves intent while being valid Python.

## Upstream search

Queries: "UP038 fix", "ruff UP038 remove nonlocal usage", "rule UP038 deletion crash linting", "nonlocal in class init UP038 error"

- related: https://github.com/astral-sh/ruff/issues/13051
  Existing report is about UP038 documentation and fix safety, not a crash on nonlocal statements.
- related: https://github.com/astral-sh/ruff/issues/7871
  Existing report is about UP038 rewriting isinstance checks incorrectly, not a crash on nonlocal statements.
- related: https://github.com/astral-sh/ruff/issues/18349
  Existing report is about UP038 deprecation warnings, not a crash on nonlocal statements.

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

- [github, closed] `UP038` documentation outdated wrt. fix safety — https://github.com/astral-sh/ruff/issues/13051
- [github, closed] UP038 rewrites code to make it slower and more verbose — https://github.com/astral-sh/ruff/issues/7871
- [github, closed] Warn about error being related to a deprecated rule — https://github.com/astral-sh/ruff/issues/18349
- [github, closed] [Bug] [DOC501 & DOC502] Numpy still docstrings with `:exc:` directive for exceptions are falsely flagged — https://github.com/astral-sh/ruff/issues/14609
- [github, closed] `# flake8: noqa` top-of-the-file comment doesn't respect `external` config — https://github.com/astral-sh/ruff/issues/10202
- [github, closed] Fixed code unformatted — https://github.com/astral-sh/ruff/issues/8619
- [github, closed] Add option to disable preview warnings — https://github.com/astral-sh/ruff/issues/8620
- [github, closed] Implement pyupgrade — https://github.com/astral-sh/ruff/issues/827

</details>
