Path: csiph.com!news.swapon.de!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 12:54:05 +0200 Organization: A noiseless patient Spider Lines: 30 Message-ID: <87610pf2uq.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> <87a8q1f9ni.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="7031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+G5wn8a/EHD9IdNkS/mwFw" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:aUQW9EWF6yXmqOW4gfB+fJM0qdk= sha1:RaaviBqoPAr+o2ExH+aON4IDrIw= Xref: csiph.com comp.lang.python:99550 Chris Angelico : > On Thu, Nov 26, 2015 at 7:27 PM, Marko Rauhamaa wrote: >> 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. > > Python defines dict-key-validity as being synonymous with hashability. > It's up to the class author to make sure the object's hash is useful. >>> hash([]) Traceback (most recent call last): File "", line 1, in TypeError: unhashable type: 'list' Annoying. > Behaviour being undefined works just fine [1] in C. It's not so > popular in Python. I don't think we want to have myriad new and > experienced programmers trying to figure out why square brackets in > dict keys are usually fine but occasionally not. But there's no way to enforce that with any of the myriad new classes. Ye blind guides, which strain at a gnat, and swallow a camel. But I say unto you, Swallow the gnat as well. Marko