Path: csiph.com!news.mixmin.net!news.albasani.net!feeder.erje.net!1.eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Date: Thu, 26 Nov 2015 19:34:47 +1100 Lines: 34 Message-ID: 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; charset=UTF-8 X-Trace: news.uni-berlin.de Ri1kP4DRipI1ntIbfaZx1ANNgKoMJtKrCdjhfmqYAiWA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'anyway.': 0.04; 'tries': 0.05; 'defines': 0.07; 'keys,': 0.07; 'undefined': 0.07; 'cc:addr :python-list': 0.09; 'brackets': 0.09; 'dict': 0.09; 'insertion': 0.09; 'likewise': 0.09; 'mutable': 0.09; "object's": 0.09; 'prevents': 0.09; 'python': 0.10; 'python.': 0.11; 'subject: \n ': 0.15; 'thu,': 0.15; 'fly.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "key's": 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'retrieval,': 0.16; 'subject:?)': 0.16; 'wrote:': 0.16; 'looked': 0.16; 'basically': 0.18; '>>>': 0.20; 'changes': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'prevent': 0.20; 'saying': 0.22; 'keys': 0.22; 'trying': 0.22; 'header:In-Reply-To:1': 0.24; 'chris': 0.26; 'figure': 0.27; 'not.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'fine': 0.28; 'behaviour': 0.29; 'dictionary': 0.29; 'hash': 0.29; 'occasionally': 0.29; 'sure,': 0.29; 'objects': 0.29; "i'm": 0.30; 'programmers': 0.30; '[1]': 0.32; 'class': 0.33; 'usually': 0.33; 'definition': 0.34; 'equal': 0.34; 'lists': 0.34; 'received:google.com': 0.35; 'nov': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'say': 0.37; 'received:209.85.213': 0.37; 'wanted': 0.37; 'received:209': 0.38; 'means': 0.39; 'why': 0.39; 'sure': 0.39; 'does': 0.39; 'enough': 0.39; 'subject:-': 0.39; 'some': 0.40; 'behavior': 0.61; 'different': 0.63; 'between': 0.65; 'manner': 0.69; '26,': 0.72; 'useful.': 0.72; 'square': 0.76; 'chrisa': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=UWxTLXjRVeirwAbJaPhjuN8StY9aHAzuMseNNpqEr9w=; b=MpneiTSA762HuXKfGMVUK+HjuTYChwi/4PZTvlqrEPvo5M+U4gnOTSiA2YoBQjdnsG FnWNDyfMaVPOKUV987EH76Qjbgn3yV1AoQiiaW6xtvYaV1WqzYNSiStHExMDTclsmpCB rMSj/gxhvmvwh+LF/9/1huk/gWrWWK1RBDg5CuSALOy80xQ0iUY9mRIKbOYuaBEabMve liEvzyVXTQTT0515CPxC8aHf17QZOYdxFrZ5UVrjMZQXWKsec0oh5MpI6fklqvuS3Yvr susV8VnuUD6MzvZmgKRckw4OQvQGYbVvO5nUhsKqXsauGKpE6Zwl2TXMsdd3QbsIwjNv SbsA== X-Received: by 10.50.30.6 with SMTP id o6mr1922521igh.94.1448526887316; Thu, 26 Nov 2015 00:34:47 -0800 (PST) In-Reply-To: <87a8q1f9ni.fsf@elektro.pacujo.net> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:99541 On Thu, Nov 26, 2015 at 7:27 PM, Marko Rauhamaa wrote: > 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. 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. 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. ChrisA [1] For some definition of "fine", anyway.