# ruff RUF019 on repo: fix changes the outcome of the project's command

Evidence sheet generated by fixhunt from a repository scan. 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 0.17.1 (fix labelled safe)
- Project: /home/sun/dev/diaghunt/demo/repo
- Command: `cd python && python3 -m unittest discover -s tests -t .` (exit 0 before, 1 after)
- Files changed by the fix: 1; reduced to 1 of 1 hunk(s) in python/toolbox/registry.py (delta debugging complete; the patch below was applied with git apply and reproduced the same difference)
- Sites reported by the rule in 1 changed file(s): 1 before, 0 after the fix
- Judge (Nemotron 3 Ultra, advisory): real, severity high. The fix replaces `key in reg and reg[key]` with `reg.get(key)`, which changes behavior when the key exists but its value is falsy (e.g., 0, False, empty string). The original code returns None for falsy values, while the fixed code returns the falsy value itself, causing the function to return a falsy value instead of None and breaking the documented contract.

## Change (reduced; applies to the project with `git apply -p1`)

```diff
--- a/python/toolbox/registry.py
+++ b/python/toolbox/registry.py
@@ -17,7 +17,7 @@
 
 def lookup(reg, key):
     """The registered value when present and truthy, else None."""
-    if key in reg and reg[key]:
+    if reg.get(key):
         return reg[key]
     return None
```

## Observed

```
exit 0 → 1
stderr last line before: OK
stderr last line after: FAILED (errors=1)
```

## Output of the command (last 40 lines)

Before:

```
(no stdout)
stderr:
..........
----------------------------------------------------------------------
Ran 10 tests in 0.007s

OK
```

After:

```
(no stdout)
stderr:
  File "/w/python/tests/test_registry.py", line 10, in test_lookup_registered
    self.assertEqual(lookup(reg, "db"), "postgres")
                     ^^^^^^^^^^^^^^^^^
  File "/w/python/toolbox/registry.py", line 20, in lookup
    if reg.get(key):
       ^^^^^^^
AttributeError: 'Registry' object has no attribute 'get'

----------------------------------------------------------------------
Ran 10 tests in 0.007s

FAILED (errors=1)
```

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

The original condition checks both that `key` exists in `reg` (`key in reg`) and that its associated value is truthy (`reg[key]`). The rewritten version uses only `if reg.get(key):`, which returns `None` for missing keys or falsy values like `False`, `0`, or empty containers—causing it to skip returning those values even when they exist in the dictionary. Thus, legitimate entries with falsy but defined values now incorrectly yield `None`, changing behavior where such cases should have returned the stored value. This violates the function’s documented intent of returning the registered value when present and truthy—not merely when get() yields a truthy result.

## Upstream search

Queries: "RUF019 fix", "RUF019 dictionary get method usage", "RUF019 conditional expression simplification", "RUF019 redundant membership check removal"

- related: https://github.com/astral-sh/ruff/issues/14011
- related: https://github.com/astral-sh/ruff/issues/12953
- related: https://github.com/astral-sh/ruff/issues/12285

## Reproduce

```sh
# /home/sun/dev/diaghunt/demo/repo: apply the change above (minimal.patch), then run the command
git apply -p1 minimal.patch
cd python && python3 -m unittest discover -s tests -t .
# or run the fixer itself on the changed files
ruff check --preview --isolated --select RUF019 --fix 'python/toolbox/registry.py'
```
