Difference of hash and __hash__()

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Fleiter

    Difference of hash and __hash__()

    Hi,

    under Python 2.2.2:
    [color=blue][color=green][color=darkred]
    >>> s = slice(None,5,No ne)
    >>> hash(s)[/color][/color][/color]
    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: unhashable type[color=blue][color=green][color=darkred]
    >>> s.__hash__()[/color][/color][/color]
    136775584

    Can anybody explain this?

    Greets,
    Stefan

  • Terry Reedy

    #2
    Re: Difference of hash and __hash__()


    "Stefan Fleiter" <stefan.fleiter @web.de> wrote in message
    news:bj2nv5$hna [email protected]. ..
    [color=blue]
    > under Python 2.2.2:
    >[color=green][color=darkred]
    > >>> s = slice(None,5,No ne)
    > >>> hash(s)[/color][/color]
    > Traceback (most recent call last):
    > File "<stdin>", line 1, in ?
    > TypeError: unhashable type[color=green][color=darkred]
    > >>> s.__hash__()[/color][/color]
    > 136775584
    >
    > Can anybody explain this?[/color]

    It looks like a bug. Extended slices were added for use by Numerical
    Python. It may never have tried to hash them or only done so only
    through the C equivavlent of s.__hash__. Extended slicing of
    sequences was, I believe, only added in 2.3.

    TJR


    Comment

    Working...