fixhunt

ruff UP038: tool crashes

tool-crashlabelled unknownprogram-bug · lowrelated
Findings / 2026-10-17T21-20-52-142Z-httm-ruff-UP038 / r2-p004ruff 0.17.14 → 4 lines2026-10-17 21:20 UTC

Hypothesis Nemotron 3 Super predicted not to fire did not fire

context managers that are not files, objects with write() but no close()

Program

before
1class Writer:
2 def write(self, s): print(s)
3with Writer() as w:
4 w.write('hello')
after
1(no fix applied)

Output

stdout beforeexit 1
(no stdout)
TypeError: 'Writer' object does not support the context manager protocol
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, not because of any rewrite applied to the program. The program itself contains no isinstance or issubclass calls, so the rule would not have matched anything. The observed failure is a tool availability issue, not a semantic change from a fix.

Explanation Nemotron 3 Super unverified

The original code creates a Writer instance via context manager but does nothing with its return value; __enter__ returns self, yet the variable w binds to that, allowing w.write('hello') to execute. If the fix attempted to remove the with statement entirely—e.g., rewriting to Writer().write('hello')—it would still call write, but the tool crash occurred because UP038 was deleted, so no rewrite was actually applied. Since the diff shows no change, the program’s behavior remains identical; any difference would stem only from a hypothetical unsafe rewrite that was never executed due to the rule’s removal. Thus, no actual behavioral change occurred—the observed failure is a tool issue, not a semantic one. (119 words)

Reproduce

file
prog.py (the before program)
minimized program
r2-p004.py
evidence sheet
r2-p004.md
regression fixture
r2-p004.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 context manager usage · Writer class __enter__ method call · with statement resource cleanup pattern

  • related astral-sh/ruff/issues/13051 Existing report is about outdated documentation for deprecated rule UP038, not a crash when selecting it.
  • related astral-sh/ruff/issues/7871 Existing report is about UP038 rewriting isinstance checks incorrectly, not a tool crash on context manager code.
  • related astral-sh/ruff/issues/18349 Existing report is about warning for deprecated rule UP038, not a crash when the rule is selected.

Details

program
Context managers without close()
hazard
context managers that are not files, objects with write() but no close()
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 (4 lines) and the fix's diff
1class Writer:
2 def write(self, s): print(s)
3with Writer() as w:
4 w.write('hello')
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/