fixhunt

ruff UP038: tool crashes

tool-crashlabelled unknownprogram-bug · lowno match
Findings / 2026-10-17T21-20-52-142Z-httm-ruff-UP038 / r1-p001ruff 0.17.19 → 2 lines2026-10-17 21:20 UTC

Hypothesis Nemotron 3 Super predicted to fire did not fire

Rewriting isinstance(x, (int, str)) to x is int | str breaks semantics when objects override __bool__ or __len__ to affect truthiness in ways unrelated to type.

Program

before
1class TruthyStr(str):
2 def __bool__(self): return True
after
1(no fix applied)

Output

stdout beforeexit 0
(no stdout)
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 was never transformed, so there is no semantic difference to evaluate.

Explanation Nemotron 3 Super unverified

The original class defines `__bool__`, making instances evaluate to `True`. Removing this method causes truthiness to fall back to string length—empty strings become falsy, non-empty remain true—but since `__str__` inherits from `str`, any instance’s value determines its boolean behavior, unlike the hardcoded `True` in `__bool__`. Thus, rewriting by deleting `__bool__` alters semantics for empty or non-empty string values, breaking equivalence. (Note: No actual diff was applied; the rule’s removal prevented the fix, but the intended change would have been unsafe.)

Reproduce

file
prog.py (the before program)
minimized program
r1-p001.py
evidence sheet
r1-p001.md
regression fixture
r1-p001.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 custom class bool method · Truthystr subclass str __bool__ override · ruff lint crash UP038 removal

no duplicate or related report 0 hits triaged

Details

program
Truthiness and Custom Boolean Logic
hazard
Rewriting isinstance(x, (int, str)) to x is int | str breaks semantics when objects override __bool__ or __len__ to affect truthiness in ways unrelated to type.
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 (9 lines) and the fix's diff
1class FalsyInt(int):
2 def __bool__(self): return False
3
4class TruthyStr(str):
5 def __bool__(self): return True
6
7x = FalsyInt(5)
8y = TruthyStr('')
9print(isinstance(x, (int, str)), isinstance(y, (int, str)))
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/