FAILURE MAP
← Case archive

FA-5161 / Context managers / Open access

Context enter binding: Replaces a false __enter__ return value with the manager label · case 01

Replaces a false __enter__ return value with the manager label and changes the required Python-language result.

Verified by executionVariant 1 · 5 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Replaces a false __enter__ return value with the manager label. The executable reproducer isolates this operation from the rest of the contract.

THE FAILURE

Replaces a false __enter__ return value with the manager label. The executable reproducer isolates this operation from the rest of the contract.

Unsuccessful approach: The alternative still fails because it returns None from __enter__ regardless of its payload.

Case contract

Bind the exact __enter__ return value to the with target, including false values. A failing __enter__ prevents body and __exit__; body exceptions still call __exit__. Inputs use the finite Python types shown in the fixtures. An error string denotes the specified caught exception, not an unhandled process failure.

Why this case matters

Runs Python standard-library language operations in a deterministic local reproducer. Literal expected answers are authored independently. Related defects share an evaluation group to avoid benchmark split leakage.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(payload, fail, body_error):
    log=[]
    class Manager:
        def __init__(self): self.value='manager'
        def __enter__(self):
            log.append('enter')
            if fail: raise ValueError('enter failed')
            return payload
        def __exit__(self,typ,exc,tb): log.append('exit'); return False
    manager=Manager()
    try:
        with manager as bound:
            log.append(['body',bound or manager.value])
            if body_error: raise KeyError('body failed')
    except Exception as exc: log.append(type(exc).__name__)
    return log
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('ordinary binding', solve('value', False, False), ['enter', ['body', 'value'], 'exit'])
check('false return remains bound', solve(0, False, False), ['enter', ['body', 0], 'exit'])
check('None return remains bound', solve(None, False, False), ['enter', ['body', None], 'exit'])
check('enter failure skips exit', solve('value', True, False), ['enter', 'ValueError'])
check('body failure still exits', solve('value', False, True), ['enter', ['body', 'value'], 'exit', 'KeyError'])
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 fixtureActualExpectedOutcome
ordinary binding['enter', ['body', 'value'], 'exit']['enter', ['body', 'value'], 'exit']Passed
false return remains bound['enter', ['body', 'manager'], 'exit']['enter', ['body', 0], 'exit']Failed
None return remains bound['enter', ['body', 'manager'], 'exit']['enter', ['body', None], 'exit']Failed
enter failure skips exit['enter', 'ValueError']['enter', 'ValueError']Passed
body failure still exits['enter', ['body', 'value'], 'exit', 'KeyError']['enter', ['body', 'value'], 'exit', 'KeyError']Passed

SHA-256 / dd1a6fec0d5f64cb3886935d68651323afc672e21eb0e932260de5e8ff18ab21

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(payload, fail, body_error):
    log=[]
    class Manager:
        def __init__(self): self.value='manager'
        def __enter__(self):
            log.append('enter')
            if fail: raise ValueError('enter failed')
            return None
        def __exit__(self,typ,exc,tb): log.append('exit'); return False
    manager=Manager()
    try:
        with manager as bound:
            log.append(['body',bound])
            if body_error: raise KeyError('body failed')
    except Exception as exc: log.append(type(exc).__name__)
    return log
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('ordinary binding', solve('value', False, False), ['enter', ['body', 'value'], 'exit'])
check('false return remains bound', solve(0, False, False), ['enter', ['body', 0], 'exit'])
check('None return remains bound', solve(None, False, False), ['enter', ['body', None], 'exit'])
check('enter failure skips exit', solve('value', True, False), ['enter', 'ValueError'])
check('body failure still exits', solve('value', False, True), ['enter', ['body', 'value'], 'exit', 'KeyError'])
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 fixtureActualExpectedOutcome
ordinary binding['enter', ['body', None], 'exit']['enter', ['body', 'value'], 'exit']Failed
false return remains bound['enter', ['body', None], 'exit']['enter', ['body', 0], 'exit']Failed
None return remains bound['enter', ['body', None], 'exit']['enter', ['body', None], 'exit']Passed
enter failure skips exit['enter', 'ValueError']['enter', 'ValueError']Passed
body failure still exits['enter', ['body', None], 'exit', 'KeyError']['enter', ['body', 'value'], 'exit', 'KeyError']Failed

SHA-256 / 2253a8d68f3a87c56eb75d241a69a671fc4e8d5bc5d1e76b98609b19958a95b4

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 5 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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:46.820375+00:00.

Case digest / 3cdfe981cc8e1edb69eebcccb0431c4df13ce9e4b576f9cf50dc361d823ce0de