[Python-ideas] Make the @contextmanager of contextlib to be a real contextmanager
Moon丶sun
uamr567 at sina.com
Sat Jan 5 07:52:16 EST 2019
As we know,when we import the module--'contextlib',we can use the decorator '@contextmanager' and keyword ‘yield’ to make a 'instance' of Class '_GeneratorContextManager' in 'contextlib' module,then we can use it like:with 'instance' as 'xx': 'code block' passBut there is a little bug,when the code block raise a error,the instance cannot run the code which after the keyword 'yield'.So I try to repair this bug, I add a method '_next()' in the Class '_GeneratorContextManager',and then insert it to the the method '__exit__',then we can make the instance like a realcontextmanager.You can cat the concrete content in the attachment.
Conmments:the method '_next()' in in line 79,the method '__exit__' in line 97.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190105/b6e9b8c1/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: _contextlib.py
Type: text/x-python
Size: 13696 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190105/b6e9b8c1/attachment-0001.py>
More information about the Python-ideas
mailing list