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 <rep...@bugs.python.org> <http://bugs.python.org/issue28516> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com