Late-binding of function defaults (was Re: What is a function parameter =[] for?)

Marko Rauhamaa marko at pacujo.net
Thu Nov 26 06:23:23 EST 2015


Chris Angelico <rosuav at gmail.com>:

> On Thu, Nov 26, 2015 at 9:54 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>>
>>    >>> hash([])
>>    Traceback (most recent call last):
>>      File "<stdin>", line 1, in <module>
>>    TypeError: unhashable type: 'list'
>>
>> Annoying.
>
> Yes, it's really annoying that you get an immediate exception instead
> of unpredictably getting bizarre failures that depend on the exact
> bucket sizes and dict size and so on. It's such a pain to get told
> exactly where the problem is.

The problem is that lists don't have __hash__ and __eq__ defined.

> Python tends to assume that programmers are intelligent people who are
> prepared to fix their mistakes.

It's not letting me in the case of list.


Marko



More information about the Python-list mailing list