Nick Coghlan added the comment:

Thanks Serhiy. I've attached a new file (issue27122_broken_cm.py) with a 
context manager that is deliberately buggy in the same way as 
contextlib._GeneratorContextManager is currently, so the new test can be made 
independent of #27122 being fixed (Greg Smith has a pending patch to make that 
CM well behaved again, which would currently lead to your new test passing for 
the wrong reasons)

issue27122_broken_cm.py also shows why I think "make it work" is the right 
answer here - the odd context chaining is tolerated in the case where the 
interpreter is implicitly setting the exception context, so I believe it should 
also be tolerated when ExitStack sets the context explicitly. If we "do the 
right thing" (where "right" = "the same as what the interpreter does") in the 
setter, then not only ExitStack, but anyone else setting __context__ should 
automatically benefit from the adjustment.

----------
Added file: http://bugs.python.org/file43382/issue27122_broken_cm.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25782>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to