[issue14963] Use an iterative implementation for contextlib.ExitStack.__exit__

Nick Coghlan report at bugs.python.org
Wed May 30 13:07:47 CEST 2012


New submission from Nick Coghlan <ncoghlan at gmail.com>:

The current implementation of contextlib.ExitStack [1] actually creates a nested series of frames when unwinding the callback stack in an effort to ensure exceptions are chained correctly, just as they would be if using nested with statements.

It would be nice to avoid this overhead by just using the one frame to iterate over the callbacks and handling correct exception chaining directly. This is likely to be a little tricky to get right, though, so the first step would be to set up a test that throws and suppresses a few exceptions and ensures the chaining when using ExitStack matches that when using nested with statements.

[1] http://hg.python.org/cpython/file/94a5bf416e50/Lib/contextlib.py#l227

----------
components: Library (Lib)
messages: 161944
nosy: ncoghlan
priority: normal
severity: normal
stage: test needed
status: open
title: Use an iterative implementation for contextlib.ExitStack.__exit__
type: enhancement
versions: Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14963>
_______________________________________


More information about the Python-bugs-list mailing list