[issue14116] Lock.__enter__() method returns True instead of self

Nick Coghlan report at bugs.python.org
Sat Feb 25 10:49:54 CET 2012


Nick Coghlan <ncoghlan at gmail.com> added the comment:

"with Lock() as lock:" doesn't make any sense - you need to share the lock with other threads or code for it be useful, which means you can't create it inline in the with statement header. Instead, you have to store it somewhere else (usually as a closure reference or a module, class or instance attribute) and then merely use it in the with statement to acquire and release it appropriately.

Absent a compelling use case, I'm inclined to reject this one - when there's no specifically useful value to return from __enter__, None, True or False are all reasonable alternatives.

----------

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


More information about the Python-bugs-list mailing list