Path: csiph.com!news.swapon.de!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 22:35:54 +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> <87610pf2uq.fsf@elektro.pacujo.net> <87wpt5dmxg.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de /On6FYUHwEQFNF6h4nFh3QtK0pMKaFQxG3GDumMUuirQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'key.': 0.07; 'reason,': 0.07; 'cc:addr:python-list': 0.09; 'defined.': 0.09; 'dict': 0.09; 'tends': 0.09; 'tuple.': 0.09; 'type:': 0.09; 'typeerror:': 0.09; 'python': 0.10; 'assume': 0.11; 'exception': 0.13; 'subject: \n ': 0.15; 'thu,': 0.15; 'bucket': 0.16; 'equality.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:?)': 0.16; 'unhashable': 0.16; 'wrote:': 0.16; '>>>': 0.20; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fix': 0.21; '"",': 0.22; 'correctly.': 0.22; 'trying': 0.22; '(most': 0.24; 'header :In-Reply-To:1': 0.24; 'chris': 0.26; 'define': 0.27; 'tired': 0.27; 'message-id:@mail.gmail.com': 0.27; 'behaving': 0.29; "i'm": 0.30; 'programmers': 0.30; 'another': 0.32; 'getting': 0.33; 'problem': 0.33; 'traceback': 0.33; 'file': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'nov': 0.35; 'stable': 0.35; 'problem.': 0.35; 'but': 0.36; 'instead': 0.36; 'there': 0.36; 'received:209.85': 0.36; 'depends': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'really': 0.37; 'received:209.85.213': 0.37; 'list.': 0.37; 'received:209': 0.38; 'subject:-': 0.39; 'where': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'is.': 0.63; '26,': 0.72; 'intelligent': 0.76; 'chrisa': 0.84; 'mistakes.': 0.84; 'pain': 0.84; 'refusing': 0.84; 'to:none': 0.91; 'available:': 0.91; 'contents,': 0.91; 'mistake': 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=L506wzm8nX7XjPJObE0RP9NgrQ+5VvddRJclfyAphCQ=; b=mBD158c7SFoBXOIm0gev0jlo0+8GitLKrL+3BlS6cGXbGi9qzmbcC+moywmhCFl8M4 MjCepf8Gin7ljyTFtOaZsjEx7lZB7fEmnd6c8wH1afn3LAorrhaskT+BqnxjzOn+O7zQ MDQ+pvXU0lTC2Fj2ERNX/HXleq+msE06J/coUVEhdrbTcG+YwCHmAVZTalY+7f/5+nLk cCzOaaFcOpS6pDyxOFiZyjTT2bz+PeKHQvV98+nGtBpniAUYO+fwjggPBxW+jHyUgAIP KNGquv2dMbjMfGGPthT0REc8/6oGLLMFK83W01lwwNULMkD0Ae9s6ntRxv66oaLLBa+S mFaw== X-Received: by 10.50.83.38 with SMTP id n6mr2564672igy.92.1448537754759; Thu, 26 Nov 2015 03:35:54 -0800 (PST) In-Reply-To: <87wpt5dmxg.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:99561 On Thu, Nov 26, 2015 at 10:23 PM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Thu, Nov 26, 2015 at 9:54 PM, Marko Rauhamaa wrote: >>> >>> >>> hash([]) >>> Traceback (most recent call last): >>> File "", line 1, in >>> TypeError: unhashable type: 'list' >>> >>> Annoying. >> >> Yes, it's really annoying that you get an immediate exception instead >> of unpredictably getting bizarre failures that depend on the exact >> bucket sizes and dict size and so on. It's such a pain to get told >> exactly where the problem is. > > The problem is that lists don't have __hash__ and __eq__ defined. They do define equality. And it depends on their contents, ergo there cannot be a stable hash. This is NOT a problem. This is the concept of unhashability behaving EXACTLY CORRECTLY. Sorry to shout, but this is another case of refusing to accept what has been explained as having good reason, and I'm getting a little tired of it. >> Python tends to assume that programmers are intelligent people who are >> prepared to fix their mistakes. > > It's not letting me in the case of list. Actually it is. Your mistake is trying to use a list as a dict key. You have a solution available: use a tuple. ChrisA