Andreas H. <ahanga...@gmx.net> added the comment:

I see your point. But even with `pop` or `remove` it is still a stack or 
stack-like. In the normal case the context managers are still released in 
reverse order as they were added. Order cannot be changed arbitrarily.

There is just the additional function of removing a single context manager 
prematurely(e.g. for graceful error recovery and such). 

I would perhaps say that a stack is the "wrong" solution to the problem of 
"programmatically combining context managers" [this is from the official 
documentaion] in the first place. I write wrong in quotes because it is of 
course not really wrong, as one wants the reverse exit order. But to adequately 
address the dynamic case one needs in my opinion the ability to prematurely 
remove context managers. Otherwise the use is limited.

Reimplemeting the desired functionality with dicts or lists does not seem 
appealing to me as the code will be 90% the same to ExitStack. It will then 
also make ExitStack obsolete. So why not integrate it there?

The unsymmetry of being able to add context managers but not being able to 
remove them also seems odd to me.

----------

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

Reply via email to