[Python-ideas] Identity dicts and sets

Christian Heimes christian at python.org
Thu Jan 3 16:10:20 CET 2013


Am 03.01.2013 04:37, schrieb Nick Coghlan:
> This can be important in some use cases:
> 
> 1. It's more correct for caching. For example, "0 + 0" should give
> "0", while "0.0 + 0.0" should give "0.0". An identity based cache will
> get this right, a value based cache will get it wrong
> (functools.lru_cache actually splits the difference and goes with a
> type+value based cache rather than a simple value based cache)

Do you mean +0.0 or -0.0? IEEE 754 zeros are always signed although +0.0
is equal to -0.0. And NaNs are always unequal to all NaNs, even to
itself. For floats we would need a type specified dict that handles
special values correctly ... Can of worms?





More information about the Python-ideas mailing list