# 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, not because the rewrite changed program semantics. The oracle observed a tool crash during linting, which is an environment or tooling issue unrelated to the fix's correctness on the source code.
- Program: minimized from 8 to 3 lines

## Reproducer

```python
fns = []
for i in range(2):
        fns.append(lambda: isinstance(x, (int, str)))
```

## 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 loop creates two lambda functions that each capture the current value of x from the enclosing scope when called; since x is unchanged between iterations, both lambdas behave identically. However, if the rewrite attempted to hoist or inline the lambda definition outside the loop—such as defining it once and reusing it—the behavior could differ if x were mutated between calls, because all instances would then share the same closure over a potentially changing x. In this specific case, x is not mutated, so the behavior remains the same, but the rewrite is still unsafe because it assumes x is invariant, which cannot be guaranteed statically. Thus, the transformation may alter semantics in contexts where x varies, making it non‑preserving in general.

## Upstream search

Queries: "UP038 fix", "ruff UP038 lambda isinstance", "rule UP038 callable expression", "UP038 type check pattern"

- related: https://github.com/astral-sh/ruff/issues/13051
  Existing report concerns outdated documentation for UP038, not a tool crash when the rule is removed.
- related: https://github.com/astral-sh/ruff/issues/7871
  Existing report is about UP038 rewriting code to be slower, not about a crash due to the rule being removed.
- related: https://github.com/astral-sh/ruff/issues/18349
  Existing report is about a warning for a deprecated rule, not a crash when selecting a removed rule.

<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>
