[issue39046] collections.abc.Reversible should not be a subclass of Hashable

2020-10-22 Thread Zac Hatfield-Dodds


Zac Hatfield-Dodds  added the comment:

I'm closing this as not-a-bug.

The way protocols just check methods does make sense (thanks for your comment 
Guido!), and a later refactoring of the code that prompted this issue (to deal 
only in concrete classes) dissolved the problem.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39046] collections.abc.Reversible should not be a subclass of Hashable

2019-12-20 Thread Ivan Levkivskyi


Change by Ivan Levkivskyi :


--
nosy: +levkivskyi

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39046] collections.abc.Reversible should not be a subclass of Hashable

2019-12-14 Thread Guido van Rossum


Guido van Rossum  added the comment:

I don't know that this is easily solved. By design, issubclass(X, Hashable) 
checks whether X defines a __hash__ method (or at least has a class attribute 
__hash__ that isn't None). And because everything ultimately derives from 
object, which *does* have a __hash__ method (that just hashes the object's 
address), everything appears hashable, *except* if it explicitly sets __hash__ 
= None.

You'll find that many classes defined in collections.abc are hashable (e.g. 
Iterable, Iterator, Sequence, Collection).

But not Set and Mapping. This is because those override __eq__, and there's 
some deep magic somewhere that sets __hash__ = None in the class dict if __eq__ 
is overridden.

You could try the following: add an explicit __hash__ = None to all the 
collection ABCs (in _collections_abc.py) that you think shouldn't define 
__hash__, and see if all the tests pass. 

However, even if they do, I suspect that this may break stuff. E.g. a class 
that inherits from Iterable but doesn't override __hash__ or __eq__ would 
suddenly no longer be usable as a dict key.

Since this is only a problem with abstract classes like Iterable or Reversible, 
maybe we should just ignore the problem?

--
nosy: +gvanrossum

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39046] collections.abc.Reversible should not be a subclass of Hashable

2019-12-14 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39046] collections.abc.Reversible should not be a subclass of Hashable

2019-12-14 Thread Lovi


Change by Lovi <1668151...@qq.com>:


--
nosy: +lovi
versions:  -Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39046] collections.abc.Reversible should not be a subclass of Hashable

2019-12-14 Thread SilentGhost


Change by SilentGhost :


--
nosy: +rhettinger, stutzbach
versions:  -Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39046] collections.abc.Reversible should not be a subclass of Hashable

2019-12-14 Thread Zac Hatfield-Dodds


New submission from Zac Hatfield-Dodds :

>>> from collections.abc import Hashable, Reversible
>>> assert issubclass(Reversible, Hashable)

However, this is trivially wrong - lists are Reversible but not Hashable, and 
there is no reason to thing that reversible objects should all be hashable.

The versions of these classes in the typing module have the same problem.

--
components: Library (Lib)
messages: 358386
nosy: Zac Hatfield-Dodds
priority: normal
severity: normal
status: open
title: collections.abc.Reversible should not be a subclass of Hashable
type: behavior
versions: Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com