Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

We already have ways to do it (use the in-operator to test membership or put a 
remove() call in a try/except).  Since already we have ways to do it and since 
those patterns are rare in practice, an API extension doesn't seem warranted.

Also, I don't really like the proposed API.  Except for methods like pop() that 
must return a value while mutating the data structure, it is rare in Python for 
mutating methods to return a value instead of None.  Another related issue is 
that it atypical and arguably non-pythonic to hide a mutation in a conditional, 
so it would lead to leas readable code.  To my eyes, in the example that 
follows, the current way is clearer and more pythonic than the proposed API:


    # Proposed way
    subscriber = request.query['subscriber']
    if subscribers.discard(subscriber):
        print('Unsubscribed')
    else:
        print('Subscriber not found')

    # Current way
    subscriber = request.query['subscriber']
    if subscriber in subscribers:
        subscribers.remove(subscriber)
        print('Unsubscribed')
    else:
        print('Subscriber not found')

Note, the latter way is also what we would use if subscribers were a dictionary 
(using del instead of remove). 
   
The proposed API is also at odds with the original intent of discard() as 
meaning "we don't care whether the element is present or not, we just want it 
gone".

----------
resolution:  -> rejected
stage:  -> resolved
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35117>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to