Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Date: Thu, 26 Nov 2015 10:27:13 +0200 Organization: A noiseless patient Spider Lines: 24 Message-ID: <87a8q1f9ni.fsf@elektro.pacujo.net> References: <87d1v5emhl.fsf@elektro.pacujo.net> <564e6a62$0$1620$c3e8da3$5496439d@news.astraweb.com> <56556DF8.1080407@rece.vub.ac.be> <878u5mns8z.fsf@elektro.pacujo.net> <874mganq2q.fsf@elektro.pacujo.net> <56565822$0$1617$c3e8da3$5496439d@news.astraweb.com> <87oaeh2qy0.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="9792"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186QQATnIYD6mxVDZk0NSjp" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:rl/K0k2LyqtmYB/HILq6bTUyBfE= sha1:vsR4i/R59MvzK2360dPJpJkdOfc= Xref: csiph.com comp.lang.python:99538 Chris Angelico : > On Thu, Nov 26, 2015 at 5:52 PM, Marko Rauhamaa wrote: >> Nothing prevents using mutable objects as keys in Python. > > Sure, you _can_. But if the key's hash changes between dict insertion > and retrieval, all manner of invariants will break, and likewise if > two equal objects have different hashes. From which you can deduce > logically that any object used as a key must remain (not) equal to > everything that it was (not) equal to from that time until it is > looked up... which basically means its value mustn't change. It must > be immutable. What I'm saying is that Python does not prevent mutable keys but tries to do that with lists and tuples. I think Python should stop trying. I have wanted to use lists as keys, and there should be no reason to allow mutable tuples. It should be enough to say that the behavior of a dictionary is undefined if a key should mutate on the fly. Marko