fixhunt

ruff UP038: tool crashes

tool-crashlabelled unknownprogram-bug · lowrelated
Findings / 2026-10-17T21-20-52-142Z-httm-ruff-UP038 / r1-p002ruff 0.17.18 → 2 lines2026-10-17 21:20 UTC

Hypothesis Nemotron 3 Super predicted to fire did not fire

Moving the union expression out of a lambda delays evaluation; if type construction has side effects (e.g., prints, state change), timing changes alter output.

Program

before
1class T:
2 def __init__(self): nonlocal counter; counter += 1
after
1(no fix applied)

Output

stdout beforeexit 1
(no stdout)
SyntaxError: no binding for nonlocal 'counter' found
stdout afternot run
(not run)
fired
0 before · 0 after
runs
each version twice, same file name, no network

Judge Nemotron 3 Ultra advisory program-bug · 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.

Explanation Nemotron 3 Super unverified

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.

Reproduce

file
prog.py (the before program)
minimized program
r1-p002.py
evidence sheet
r1-p002.md
regression fixture
r1-p002.py the minimized program with a header stating the observed change, for the tool's test suite
python3 prog.py
ruff check --preview --isolated --select UP038 --fix prog.py
python3 prog.py

Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra

UP038 fix · ruff UP038 remove nonlocal usage · rule UP038 deletion crash linting · nonlocal in class init UP038 error

Details

program
Lambda Evaluation Timing with Side-Effecting Types
hazard
Moving the union expression out of a lambda delays evaluation; if type construction has side effects (e.g., prints, state change), timing changes alter output.
oracle
lint crashed: ruff failed Cause: Rule `UP038` was removed and cannot be selected.
run
2026-10-17T21-20-52-142Z-httm-ruff-UP038
generated program (8 lines) and the fix's diff
1counter = 0
2class T:
3 def __init__(self): nonlocal counter; counter += 1
4
5f = lambda x: isinstance(x, (T, int))
6print(f(T()), counter)
7counter = 0
8print([f(T()) for _ in range(2)], counter)
rule documentation given to the models
# non-pep604-isinstance (UP038)

Derived from the **pyupgrade** linter.

Fix is always available.

## Removed
This rule was removed as using [PEP 604] syntax in `isinstance` and `issubclass` calls
isn't recommended practice, and it incorrectly suggests that other typing syntaxes like [PEP 695]
would be supported by `isinstance` and `issubclass`. Using the [PEP 604] syntax
is also slightly slower.

## What it does
Checks for uses of `isinstance` and `issubclass` that take a tuple
of types for comparison.

## Why is this bad?
Since Python 3.10, `isinstance` and `issubclass` can be passed a
`|`-separated union of types, which is consistent
with the union operator introduced in [PEP 604].

Note that this results in slower code. Ignore this rule if the
performance of an `isinstance` or `issubclass` check is a
concern, e.g., in a hot loop.

## Example
```python
isinstance(x, (int, float))
```

Use instead:
```python
isinstance(x, int | float)
```

## Options
- `target-version`

## References
- [Python documentation: `isinstance`](https://docs.python.org/3/library/functions.html#isinstance)
- [Python documentation: `issubclass`](https://docs.python.org/3/library/functions.html#issubclass)

[PEP 604]: https://peps.python.org/pep-0604/
[PEP 695]: https://peps.python.org/pep-0695/