Return False from __contains__ method if object not hashable for set and dict.

Now if do something like `[] in set()` python raise an exception, but if an object isn't hashable then we know for sure that it isn't in the set. Propose return False for these cases. What do you think?

25.10.21 18:49, Kazantcev Andrey пише:
Now if do something like `[] in set()` python raise an exception, but if an object isn't hashable then we know for sure that it isn't in the set. Propose return False for these cases. What do you think?
What was changed since this topic was discussed last time?

On Mon, Oct 25, 2021 at 07:17:18PM +0300, Serhiy Storchaka wrote:
I'm surprised that wasn't already the case. Serhiy wrote:
What was changed since this topic was discussed last time?
We're eight years older and wiser perhaps? https://mail.python.org/archives/list/python-dev@python.org/thread/UOPPG7UM4... It seems to me that there are good arguments to be made for both behaviours, but none are strong enough to break backwards compatibility. -- Steve

25.10.21 18:49, Kazantcev Andrey пише:
Now if do something like `[] in set()` python raise an exception, but if an object isn't hashable then we know for sure that it isn't in the set. Propose return False for these cases. What do you think?
What was changed since this topic was discussed last time?

On Mon, Oct 25, 2021 at 07:17:18PM +0300, Serhiy Storchaka wrote:
I'm surprised that wasn't already the case. Serhiy wrote:
What was changed since this topic was discussed last time?
We're eight years older and wiser perhaps? https://mail.python.org/archives/list/python-dev@python.org/thread/UOPPG7UM4... It seems to me that there are good arguments to be made for both behaviours, but none are strong enough to break backwards compatibility. -- Steve
participants (3)
-
Kazantcev Andrey
-
Serhiy Storchaka
-
Steven D'Aprano