# ruff PLR1733: 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: PLR1733 (tool labels the fix: unknown, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): real, severity high. The rule assumes that the value yielded by .items() is identical to the value returned by __getitem__, but the program uses a custom dict subclass where __getitem__ returns an awaitable while the stored value is an int. The rewrite changes await d[k] (which awaits the async result) to await v (which tries to await an int), causing a TypeError.
- Program: minimized from 17 to 11 lines

## Reproducer

```python
async def get_val(k):
    return k
class AwaitableDict(dict):
    def __getitem__(self, key):
        return get_val(key)
async def main():
    d = AwaitableDict({'x': 1})
    for k, v in d.items():
        x = await d[k]  # triggers PLR1733: would become await v — but v is int, not awaitable
import asyncio
result = asyncio.run(main())
```

## Commands

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

## Observed

```
exit 0 → 1
stderr before: (none)
stderr after: TypeError: object int can't be used in 'await' expression
```

## Diff applied by the fix

```diff
--- orig.py	2026-10-22 13:34:58.178549629 -0400
+++ fixed.py	2026-10-22 13:35:01.283601992 -0400
@@ -6,6 +6,6 @@
 async def main():
     d = AwaitableDict({'x': 1})
     for k, v in d.items():
-        x = await d[k]  # triggers PLR1733: would become await v — but v is int, not awaitable
+        x = await v  # triggers PLR1733: would become await v — but v is int, not awaitable
 import asyncio
 result = asyncio.run(main())
```

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

The original code awaits `d[k]`, which invokes `__getitem__` returning `get_val(k)`—a coroutine that yields the integer value of `k`. After rewriting to `await v`, it attempts to await the loop variable `v`, which is the actual dictionary value (an integer), not a coroutine. Since integers are not awaitable, this raises a TypeError, changing behavior from successful execution to failure.

## Upstream search

Queries: "PLR1733 fix", "PLR1733 dict items loop", "await expression optimization", "ruff autofix await variable"

- related: https://github.com/astral-sh/ruff/issues/25182
  same rule PLR1733 but different construct (else-clause dictionary access vs for-loop items iteration)
- related: https://github.com/astral-sh/ruff/issues/29422
  same rule PLR1733 mentioned among other fix bugs but no detail on this construct
- related: https://github.com/astral-sh/ruff/issues/25150
  same rule PLR1733 false positive but different construct (else-clause vs for-loop items iteration)

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

- [github, open] Additional false positives in `PLR1733` and `PLR1736` — https://github.com/astral-sh/ruff/issues/25182
- [github, open] A few more: missed reports vs flake8/pylint, plus two fix bugs (B012, F402, F823, SIM102, SIM401, PLW1641, PLR1736, PLW0406, N801, UP034) — https://github.com/astral-sh/ruff/issues/29422
- [github, closed] unused-function-argument not silenced by prefixed underscore if variable name is "次" — https://github.com/astral-sh/ruff/issues/28721
- [github, open] Implement Pylint — https://github.com/astral-sh/ruff/issues/970
- [github, closed] PLR1733 false positive — https://github.com/astral-sh/ruff/issues/25150
- [github, closed] Pack of fuzzer Autofix/Infinite loop errors [2] — https://github.com/astral-sh/ruff/issues/8402
- [github, closed] Don't parenthesize unsplittable expressions to make comments fit — https://github.com/astral-sh/ruff/issues/8041
- [tavily] [syntax-errors] Remaining syntax errors raised by the compiler · Issue #17412 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/17412
- [tavily] Feature Request : C0103/invalid-name: Allow specifying valid variable and constant patterns with regular expressions. · Issue #10629 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/10629
- [tavily] F841 "Undefined name" false positive in exception-nested-closure · Issue #6878 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/6878
- [tavily] Autofix S101 · Issue #7635 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/7635
- [tavily] add rule to catch `any` and `callable` in typing context · Issue #17224 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/17224
- [tavily] Option to sort re-exports in `__all__` (`sort_exports` from isort) · Issue #1198 · astral-sh/ruff · GitHub — https://github.com/astral-sh/ruff/issues/1198

</details>
