Brett Cannon added the comment:

The reason I suggested the ABC for context managers is mostly to provide a way 
to help people make sure to implement __enter__() and to provide a default 
__exit__() which has the proper signature (I personally always forget how many 
arguments __exit__() takes and what the arguments are past the first one). The 
type part of this feature request is because I realized that a type hint of 
"context manager" isn't really useful, but "context manager returning ..." is 
since a `with` statement does introduce a new variable. IOW none of this has 
anything to do with isinstance() and it's all about easing the use of the 
context manager interface and proper type hints for the `with` statement.

As for a new module analogous to the `types` module just for ABCs, that's fine 
by me. I had the same reaction you did, Raymond, about putting it in 
collections.abc. I can open another issue for that idea and leave this open as 
it's somewhat orthogonal to what I'm proposing.

----------

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

Reply via email to