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

Marko Rauhamaa marko at pacujo.net
Thu Nov 26 01:52:07 EST 2015


Steven D'Aprano <steve at pearwood.info>:

> Making tuples mutable would break their use as dictionary keys, which is a
> *critical* use.

No, it wouldn't. Any object that provides __hash__() and __eq__() can be
used as a key.

Nothing prevents using mutable objects as keys in Python.

    Egon Spengler: There's something very important I forgot to tell you.
    Peter Venkman: What?
    Spengler: Don't use mutable keys.
    Venkman: Why?
    Spengler: It would be bad.
    Venkman: I'm fuzzy on the whole good/bad thing. What do you mean,
       "bad"?
    Spengler: Try to imagine all life as you know it stopping
        instantaneously and every molecule in your body exploding at the
        speed of light.
    Ray Stantz: Total protonic reversal!
    Venkman: Right. That's bad. Okay. All right. Important safety tip.
        Thanks, Egon.


Marko



More information about the Python-list mailing list