[issue28516] contextlib.ExitStack.__enter__ has trivial but undocumented behavior
Walker Hale IV
report at bugs.python.org
Sun Oct 23 22:36:51 EDT 2016
New submission from Walker Hale IV:
contextlib.ExitStack implies but does not explicitly state that its __enter__ method trivially returns self.
This means that if a user invokes pop_all and then uses the resulting ExitStack instance in a with statement, the user will be relying on undocumented behavior. Avoiding undocumented behavior forces the user to instead use a tedious try/finally construct, partially defeating the elegance of context managers.
I propose that:
1. The ExitStack.__enter__ method be briefly mentioned as doing nothing besides returning self.
2. The example in pop_all documentation be expanded to show a following with statement that uses the new ExitStack instance.
The discussion in section 29.6.3.2 is not sufficient to make this trivial point clear.
----------
messages: 279296
nosy: Walker Hale IV
priority: normal
severity: normal
status: open
title: contextlib.ExitStack.__enter__ has trivial but undocumented behavior
versions: Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28516>
_______________________________________
More information about the Python-bugs-list
mailing list