• Guido van Rossum's avatar
    Fix of SF bug #475877 (Mutable subtype instances are hashable). · dbb53d99
    Guido van Rossum yazdı
    Rather than tweaking the inheritance of type object slots (which turns
    out to be too messy to try), this fix adds a __hash__ to the list and
    dict types (the only mutable types I'm aware of) that explicitly
    raises an error.  This has the advantage that list.__hash__([]) also
    raises an error (previously, this would invoke object.__hash__([]),
    returning the argument's address); ditto for dict.__hash__.
    
    The disadvantage for this fix is that 3rd party mutable types aren't
    automatically fixed.  This should be added to the rules for creating
    subclassable extension types: if you don't want your object to be
    hashable, add a tp_hash function that raises an exception.
    
    Also, it's possible that I've forgotten about other mutable types for
    which this should be done.
    dbb53d99
listobject.c 44.5 KB