FAILURE MAP
← Case archive

FA-5166 / Context managers / Open access

Context enter binding: Returns None from __enter__ regardless of its payload · case 01

Returns None from __enter__ regardless of its payload and changes the required Python-language result.

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

ROOT CAUSE

Returns None from __enter__ regardless of its payload. 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 calls __enter__ again while constructing the with-body binding.

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

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',manager.__enter__()])
            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', 'enter', ['body', 'value'], 'exit']['enter', ['body', 'value'], 'exit']Failed
false return remains bound['enter', 'enter', ['body', 0], 'exit']['enter', ['body', 0], 'exit']Failed
None return remains bound['enter', 'enter', ['body', None], 'exit']['enter', ['body', None], 'exit']Failed
enter failure skips exit['enter', 'ValueError']['enter', 'ValueError']Passed
body failure still exits['enter', 'enter', ['body', 'value'], 'exit', 'KeyError']['enter', ['body', 'value'], 'exit', 'KeyError']Failed

SHA-256 / 800f626b8c5e75bb97f4acdc203cd48a7dac0e942000074da36eb6fc4f0d1991

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

Case digest / fba7bb4eae91f7c9333c9b3ac3db884de7c38ccf4c8596e84e81b40df4cd4fbb