This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2008年07月02日 23:06 by rhettinger, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg69140 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2008年07月02日 23:06 | |
In the Hashable ABC, there is a peculiar code fragment: if "__hash__" in B.__dict__: if B.__dict__["__hash__"]: return True break When would the innermost if-statement ever be False? Is there a reason to define __hash__ to be something that evaluates to False? |
|||
| msg69143 - (view) | Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) | Date: 2008年07月02日 23:10 | |
This is precisely under discussion in issue2235: if a base class is hashable, a derived class may set __hash__ to None, and disallow hashing. |
|||
| msg69145 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2008年07月02日 23:24 | |
I don't think we should build in explicit support for bad designs that violate the Liskov substitution principle. Are there any valid use cases for wanting non-hashable subclasses of hashable classes? If for some reason, this feature survives, it would be better to use NotImplemented instead of None. |
|||
| msg69147 - (view) | Author: Guido van Rossum (gvanrossum) * (Python committer) | Date: 2008年07月02日 23:32 | |
There are tons of ways to violate Liskov in Python. Liskov is not always the right rule. NotImplemented is not appropriate -- it is only used as a magic return value from binary functions. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:36 | admin | set | github: 47513 |
| 2008年07月02日 23:32:18 | gvanrossum | set | status: open -> closed resolution: rejected messages: + msg69147 |
| 2008年07月02日 23:24:04 | rhettinger | set | messages:
+ msg69145 versions: + Python 2.6, - Python 2.5 |
| 2008年07月02日 23:10:36 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages: + msg69143 |
| 2008年07月02日 23:06:53 | rhettinger | create | |