Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Antoon Pardon Newsgroups: comp.lang.python Subject: Re: Late-binding of function defaults (was Re: What is a function parameter =[] for?) Date: Thu, 26 Nov 2015 09:45:46 +0100 Lines: 29 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 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de +e4ZTA69Obawl4on9EDonwZMXnpOWCPWtBKBdbMAk9Bg== 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; 'received:134': 0.05; 'tries': 0.05; 'keys,': 0.07; 'undefined': 0.07; 'dict': 0.09; 'insertion': 0.09; 'likewise': 0.09; 'mutable': 0.09; 'prevents': 0.09; 'python': 0.10; 'python.': 0.11; 'subject: \n ': 0.15; 'thu,': 0.15; 'dictionary,': 0.16; 'dictionary.': 0.16; 'fly.': 0.16; "key's": 0.16; 'received:ac.be': 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; 'prevent': 0.20; 'saying': 0.22; 'keys': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; "doesn't": 0.26; 'chris': 0.26; 'dictionary': 0.29; 'hash': 0.29; 'sure,': 0.29; 'objects': 0.29; "i'm": 0.30; 'received:be': 0.30; 'maybe': 0.33; 'problem': 0.33; 'equal': 0.34; 'lists': 0.34; 'could': 0.35; 'nov': 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'being': 0.37; 'say': 0.37; 'wanted': 0.37; 'means': 0.39; 'does': 0.39; 'enough': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'behavior': 0.61; 'different': 0.63; 'between': 0.65; 'manner': 0.69; '26,': 0.72; 'introduce': 0.79; 'schreef': 0.84 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnEJACvGVlaGuA9G/2dsb2JhbABehFcBJcAIhg8CggMBAQEBAQGFQAEBBCNmCxgCAgUhAgIPAhA2EwYCAogVAxKuAotGDUeEHAEBCAIhgQGFU4R+glOCVIJOgUQFlleLP4F2iRCLeIdWY4IQHhaBQXGFYAEBAQ User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.8.0 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:99545 Op 26-11-15 om 09:27 schreef Marko Rauhamaa: > 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. Maybe python could introduce a dictionary that copies the keys in and out the dictionary. In that case keys can be mutable without that being a problem for the dictionary, because the dictionary works with it's own copy of the key that it doesn't mutate. -- Antoon.