Skip to content

"lock.__exit__ == lock.release" should be False #55403

Closed

Description

@dghjfrdj
mannequin
BPO 11194
Nosy @bitdancer

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 = None
closed_at = <Date 2011-02-11.21:57:51.298>
created_at = <Date 2011-02-11.17:40:57.464>
labels = ['invalid', 'type-bug', 'library']
title = '"lock.__exit__ == lock.release" should be False'
updated_at = <Date 2011-02-11.21:57:51.297>
user = 'https://bugs.python.org/dghjfrdj'

bugs.python.org fields:

activity = <Date 2011-02-11.21:57:51.297>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2011-02-11.21:57:51.298>
closer = 'r.david.murray'
components = ['Library (Lib)']
creation = <Date 2011-02-11.17:40:57.464>
creator = 'dghjfrdj'
dependencies = []
files = []
hgrepos = []
issue_num = 11194
keywords = []
message_count = 4.0
messages = ['128409', '128414', '128425', '128431']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'dghjfrdj']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue11194'
versions = ['Python 3.1', 'Python 2.7', 'Python 3.2', 'Python 3.3']

Activity

  1. dghjfrdj commented on Feb 11, 2011

    dghjfrdjmannequin
    MannequinAuthor

    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

  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Feb 11, 2011
  3. bitdancer commented on Feb 11, 2011

    @bitdancer
    Member

    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?

  4. dghjfrdj commented on Feb 11, 2011

    dghjfrdjmannequin
    MannequinAuthor

    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.

  5. bitdancer commented on Feb 11, 2011

    @bitdancer
    Member

    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.

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions