[issue25609] Add a ContextManager ABC and type

Martin Panter report at bugs.python.org
Sat Jan 2 17:18:21 EST 2016


Martin Panter added the comment:

What would your context manager base class do? I presume you supply a default __enter__() that does nothing, or perhaps just returns self.

You mentioned having a default __exit__() but I am having trouble seeing how it would be useful. A context manager is only really useful if it does something interesting in __exit__(), and for that, the programmer has to write their own version and remember its signature.

One option to simplify __exit__() that I used to use is a base class that defers to an abstract close() method with no parameters. But since ExitStack is now available, I am finding that is good enough instead.

----------
nosy: +martin.panter

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


More information about the Python-bugs-list mailing list