# ruff RUF046: fix changes program behavior

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: RUF046 (tool labels the fix: unknown, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): introspection-only, severity low. The fix removes the redundant `int()` call from the lambda's source code, which changes the text returned by `inspect.getsource`. This is purely a source-code introspection difference; the runtime behavior of the lambda (returning 8) is unchanged.
- Program: minimized from 9 to 3 lines

## Reproducer

```python
import inspect
src = inspect.getsource(lambda: int(5 + 3))
print('Source length of int(5+3):', len(src.strip()))
```

## Commands

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

## Observed

```
stdout before:
Source length of int(5+3): 43
stdout after:
Source length of int(5+3): 40
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:44:01.708908787 -0400
+++ fixed.py	2026-10-22 13:44:04.790703920 -0400
@@ -1,3 +1,3 @@
 import inspect
-src = inspect.getsource(lambda: int(5 + 3))
+src = inspect.getsource(lambda: (5 + 3))
 print('Source length of int(5+3):', len(src.strip()))
```

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

The original lambda calls `int` on the result of `5 + 3`, producing integer value 8; its source includes the call to `int`. After rewriting, the lambda returns only the expression `(5 + 3)` without applying `int`, so its source text omits those characters, changing the string returned by `inspect.getsource`. Consequently, stripping whitespace yields a shorter string, reducing its length from 43 to 40, which alters the printed output. The transformation removes a function call that affects the lambda’s source representation, violating semantic equivalence under `inspect.getsource`.

## Upstream search

Queries: "RUF046 fix", "RUF046 lambda call to builtin", "inspect.getsource lambda simplification", "ruff remove redundant constructor"

- related: https://github.com/astral-sh/ruff/issues/15263
  RUF046 fix defect involving newline before call expression's opening parenthesis, different construct than lambda-wrapped int().
- related: https://github.com/astral-sh/ruff/issues/15226
  RUF046 fix crash/behavior change when cast expression contains a newline, different trigger than lambda context.
- related: https://github.com/astral-sh/ruff/issues/14793
  Design complaint that RUF046 handles both round() and int() together, not the specific lambda int() removal bug.

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

- [github, closed] unused-function-argument not silenced by prefixed underscore if variable name is "次" — https://github.com/astral-sh/ruff/issues/28721
- [github, closed] Please remove all rules without an automated fix from default rules — https://github.com/astral-sh/ruff/issues/27177
- [github, closed] RUF046 fix is wrong when a newline appears before a call expression’s opening parenthesis — https://github.com/astral-sh/ruff/issues/15263
- [github, closed] RUF046 fix introduces a syntax error when the cast expression contains a newline — https://github.com/astral-sh/ruff/issues/15226
- [github, closed] `RUF046` is doing two things instead of one — https://github.com/astral-sh/ruff/issues/14793
- [github, closed] `itertools.starmap(func, zip(...))` — https://github.com/astral-sh/ruff/issues/15481
- [github, open] Suggestion: Implement Sourcery rules — https://github.com/astral-sh/ruff/issues/11060
- [github, open] Support for refurb — https://github.com/astral-sh/ruff/issues/1348
- [github, open] Document fix safety — https://github.com/astral-sh/ruff/issues/15584
- [github, open] Implement Pylint — https://github.com/astral-sh/ruff/issues/970
- [github, open] Feature: Port Sonar's Python scanner checks — https://github.com/astral-sh/ruff/issues/4935
- [github, closed] FURB164 fix should validate arguments and should usually be marked unsafe — https://github.com/astral-sh/ruff/issues/19076

</details>
