FA-4746 / Scoped mappings / Open access
Chainmap setdefault observes outer binding · case 01
The operation returns a result or retained state that violates this contract: setdefault returns an existing binding from any scope without inserting into the first scope; only an absent key is inserted.
ROOT CAUSE
Applying setdefault directly to the first map ignores inherited bindings.
VERIFIED REPAIR
setdefault returns an existing binding from any scope without inserting into the first scope; only an absent key is inserted.
Unsuccessful approach: Boolean fallback overwrites falsy inherited values and inserts unnecessary shadows.
Case contract
setdefault returns an existing binding from any scope without inserting into the first scope; only an absent key is inserted. Inputs are the finite Python values shown by the executable fixtures; no concurrent execution is assumed.
Why this case matters
A controlled local-runtime regression for collection APIs, language semantics, or ownership wrappers. Fixtures include boundary and interaction cases.
1 / The failure
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from collections import Counter, ChainMap, deque
import heapq
N = 1
observations = []
def solve(x, y=None):
a=[dict(m) for m in x]; v=a[0].setdefault(y[0],y[1]); return [v,a]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('outer binding remains outer', solve([{}, {'a': 1}], ['a', 2]), [1, [{}, {'a': 1}]])
check('outer None retained', solve([{}, {'a': None}], ['a', 2]), [None, [{}, {'a': None}]])
check('absent inserted', solve([{}, {}], ['a', 2]), [2, [{'a': 2}, {}]])
check('inner existing', solve([{'a': 1}], ['a', 2]), [1, [{'a': 1}]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| outer binding remains outer | [2, [{'a': 2}, {'a': 1}]] | [1, [{}, {'a': 1}]] | Failed |
| outer None retained | [2, [{'a': 2}, {'a': None}]] | [None, [{}, {'a': None}]] | Failed |
| absent inserted | [2, [{'a': 2}, {}]] | [2, [{'a': 2}, {}]] | Passed |
| inner existing | [1, [{'a': 1}]] | [1, [{'a': 1}]] | Passed |
SHA-256 / 06d30ce4a95345efce083816c7a15539f74f513074b624d63a19ec70ebb6e954
2 / The unsuccessful fix
Exit 1"""Failure Map reference implementation. Python standard library only."""
import json
from collections import Counter, ChainMap, deque
import heapq
N = 1
observations = []
def solve(x, y=None):
c=ChainMap(*[dict(m) for m in x]); v=c.get(y[0]) or y[1]; c[y[0]]=v; return [v,c.maps]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('outer binding remains outer', solve([{}, {'a': 1}], ['a', 2]), [1, [{}, {'a': 1}]])
check('outer None retained', solve([{}, {'a': None}], ['a', 2]), [None, [{}, {'a': None}]])
check('absent inserted', solve([{}, {}], ['a', 2]), [2, [{'a': 2}, {}]])
check('inner existing', solve([{'a': 1}], ['a', 2]), [1, [{'a': 1}]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| outer binding remains outer | [1, [{'a': 1}, {'a': 1}]] | [1, [{}, {'a': 1}]] | Failed |
| outer None retained | [2, [{'a': 2}, {'a': None}]] | [None, [{}, {'a': None}]] | Failed |
| absent inserted | [2, [{'a': 2}, {}]] | [2, [{'a': 2}, {}]] | Passed |
| inner existing | [1, [{'a': 1}]] | [1, [{'a': 1}]] | Passed |
SHA-256 / 0072b7eeeee66ce77d7c344334f24d2529b8a080f3e0c1823efcf362db817d77
3 / The verified repair
Exit 0"""Failure Map reference implementation. Python standard library only."""
import json
from collections import Counter, ChainMap, deque
import heapq
N = 1
observations = []
def solve(x, y=None):
c=ChainMap(*[dict(m) for m in x]); v=c.setdefault(y[0],y[1]); return [v,c.maps]
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('outer binding remains outer', solve([{}, {'a': 1}], ['a', 2]), [1, [{}, {'a': 1}]])
check('outer None retained', solve([{}, {'a': None}], ['a', 2]), [None, [{}, {'a': None}]])
check('absent inserted', solve([{}, {}], ['a', 2]), [2, [{'a': 2}, {}]])
check('inner existing', solve([{'a': 1}], ['a', 2]), [1, [{'a': 1}]])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
| Boundary fixture | Actual | Expected | Outcome |
|---|---|---|---|
| outer binding remains outer | [1, [{}, {'a': 1}]] | [1, [{}, {'a': 1}]] | Passed |
| outer None retained | [None, [{}, {'a': None}]] | [None, [{}, {'a': None}]] | Passed |
| absent inserted | [2, [{'a': 2}, {}]] | [2, [{'a': 2}, {}]] | Passed |
| inner existing | [1, [{'a': 1}]] | [1, [{'a': 1}]] | Passed |
SHA-256 / aea5378df51cf0e0dca683bc37113a6676049bb3831418522d62c1a599435417
Verification & scope
This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.
Observations recorded using Python 3.12.14 at 2026-09-29T14:37:42.190518+00:00.
Case digest / ac20850c4730ae9a24f2de0a762fd7ac4ce1dc85a2653595d084e9afbef36335