[New-bugs-announce] [issue14116] Lock.__enter__() method returns True instead of self

sbt report at bugs.python.org
Fri Feb 24 22:03:01 CET 2012

New submission from sbt <shibturn at gmail.com>:

The __enter__() methods of Lock, RLock, Semaphore and Condition in threading (and multiprocessing) all return True.  This seems to contradict the documentation for the context protocol which says


    Enter the runtime context and return either this object or 
    another object related to the runtime context. The value 
    returned by this method is bound to the identifier in the
    as clause of with statements using this context manager.


I don't think True qualifies as "another object related to the runtime context".

It looks like an oversight caused by making __enter__() an alias for acquire().  Is it reasonable to change this for 3.3?  I tripped over the issue when I tried writing

  with Condition() as c:

components: Library (Lib)
messages: 154161
nosy: sbt
priority: normal
severity: normal
status: open
title: Lock.__enter__() method returns True instead of self
type: behavior
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list