[issue35117] set.discard should return True or False based on if element existed.

2018-11-01 Thread tzickel
tzickel added the comment: I would think that the .discard is the equivalent of .pop in dict. (instead of wasting time once checking and once removing, also the data in a set is the data, there is no value to check). Even the standard lib has lots of usage of dict.pop(key, None) to not

[issue35117] set.discard should return True or False based on if element existed.

2018-10-31 Thread Raymond Hettinger
Raymond Hettinger 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

[issue35117] set.discard should return True or False based on if element existed.

2018-10-30 Thread Windson Yang
Windson Yang added the comment: I guess we can implement using ref_count? However, I agreed "The use of variables that haven't been defined or set (implicitly or explicitly) is almost always a bad thing in any language since it indicates that the logic of the program hasn't been thought

[issue35117] set.discard should return True or False based on if element existed.

2018-10-30 Thread Raymond Hettinger
Change by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe:

[issue35117] set.discard should return True or False based on if element existed.

2018-10-30 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: try: s.remove(x) except KeyError: # did not exist else: # existed But catching exception in Python is expensive. -- nosy: +rhettinger, serhiy.storchaka ___ Python tracker

[issue35117] set.discard should return True or False based on if element existed.

2018-10-30 Thread tzickel
New submission from tzickel : Sometimes you want to do something based on if the item existed before removal, so instead of checking if it exists, then removing and doing something, if would be nice to make the function return True or False based on if the element existed. --