FAILURE MAP
← Case archive

FA-5156 / Context managers / Open access

Context enter binding: Binds the manager object label instead of its __enter__ result · case 01

Binds the manager object label instead of its __enter__ result and changes the required Python-language result.

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

ROOT CAUSE

Binds the manager object label instead of its __enter__ result. The executable reproducer isolates this operation from the rest of the contract.

VERIFIED REPAIR

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__.

Unsuccessful approach: The alternative still fails because it replaces a false __enter__ return value with the manager label.

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',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', 'manager'], 'exit']['enter', ['body', 'value'], 'exit']Failed
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', 'manager'], 'exit', 'KeyError']['enter', ['body', 'value'], 'exit', 'KeyError']Failed

SHA-256 / 1e347d27e380eec6baaf824a3a2026081931f7aa0acf869cc5f8ed1b5d24c587

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 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

3 / The verified repair

Exit 0
"""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])
            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', 0], 'exit']['enter', ['body', 0], 'exit']Passed
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', 'value'], 'exit', 'KeyError']['enter', ['body', 'value'], 'exit', 'KeyError']Passed

SHA-256 / 73b8659395ff0179c5440f6dec07c2cc5f47e44c7f652f79e33d9410b3729621

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

Case digest / 7a46c40ce308c3495f74fbf62bd6f01e669a944843d9726f9bef72e65086704d