You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"lock.__exit__ == lock.release" should be False #55403
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2011-02-11.21:57:51.298>created_at=<Date2011-02-11.17:40:57.464>labels= ['invalid', 'type-bug', 'library']
title='"lock.__exit__ == lock.release" should be False'updated_at=<Date2011-02-11.21:57:51.297>user='https://bugs.python.org/dghjfrdj'
if 'lock' is a threading.Lock, the functions lock.__exit__() and lock.release() are different. The former takes 3 arguments, while the latter takes no argument. However, "lock.__exit__ == lock.release" returns True. Shouldn't it return False ?
Best regards,
O.C.
Details:
In [20]: lock=threading.Lock()
In [21]: lock.acquire()
In [22]: lock.__exit__(None,None,None)
In [23]: lock.locked()
Out[23]: False
In [24]: lock.acquire()
In [25]: lock.release(None,None,None)
TypeError: release() takes no arguments (3 given)
In [26]: lock.__exit__==lock.release
Out[26]: True
Well, under the (C) hood, it is in fact the same method, it just takes a variable number of arguments (and ignores them, in the __exit__ case). The fact that the arguments are rejected in the 'release' case is because of how the C function is defined as a Python method using the C API. So the result of the boolean test is more accurate than a False report would be, although not precise.
I don't *think* there is any bug to fix here. Do you have a use case that this impacts?
dghjfrdj commented on Feb 11, 2011
dghjfrdjmannequin
MannequinAuthor
More actions
Do you have a use case that this impacts?
No, I can live with it. It was rather a point about clarity and consistency. For example, the difference between Lock and RLock:
lock.__exit__==lock.release -> True
rlock.__exit__==rlock.release -> False
We came on that topic when using 'with' statements with exceptions and 'returns'. I wanted to check and understand the details, and I was confused by the fact that:
three arguments will be given to lock.__exit__()
lock.__exit__ is "the same" as lock.release
lock.release takes no argument
These propositions are all true, but seem contradictory. The meaning of "the same" is not obvious in this case.
Previous to Python3.2, RLock was implemented in Python, and the two methods are actually different methods there. In Python3.2, rlock.release == rlock.__exit__ is True.
Activity
dghjfrdj commentedon Feb 11, 2011
Hello,
if 'lock' is a threading.Lock, the functions lock.__exit__() and lock.release() are different. The former takes 3 arguments, while the latter takes no argument. However, "lock.__exit__ == lock.release" returns True. Shouldn't it return False ?
Best regards,
O.C.
Details:
In [20]: lock=threading.Lock()
In [21]: lock.acquire()
In [22]: lock.__exit__(None,None,None)
In [23]: lock.locked()
Out[23]: False
In [24]: lock.acquire()
In [25]: lock.release(None,None,None)
TypeError: release() takes no arguments (3 given)
In [26]: lock.__exit__==lock.release
Out[26]: True
bitdancer commentedon Feb 11, 2011
Well, under the (C) hood, it is in fact the same method, it just takes a variable number of arguments (and ignores them, in the __exit__ case). The fact that the arguments are rejected in the 'release' case is because of how the C function is defined as a Python method using the C API. So the result of the boolean test is more accurate than a False report would be, although not precise.
I don't *think* there is any bug to fix here. Do you have a use case that this impacts?
dghjfrdj commentedon Feb 11, 2011
No, I can live with it. It was rather a point about clarity and consistency. For example, the difference between Lock and RLock:
lock.__exit__==lock.release -> True
rlock.__exit__==rlock.release -> False
We came on that topic when using 'with' statements with exceptions and 'returns'. I wanted to check and understand the details, and I was confused by the fact that:
These propositions are all true, but seem contradictory. The meaning of "the same" is not obvious in this case.
bitdancer commentedon Feb 11, 2011
Yeah, sometimes you just have to read the source.
Previous to Python3.2, RLock was implemented in Python, and the two methods are actually different methods there. In Python3.2, rlock.release == rlock.__exit__ is True.