Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Procedures and functions [was Re: Why not allow empty code blocks?] Date: Sun, 31 Jul 2016 16:55:09 +1000 Lines: 26 Message-ID: References: <579B1ABB.1070500@rece.vub.ac.be> <579c2095$0$22142$c3e8da3$5496439d@news.astraweb.com> <579cbded$0$1605$c3e8da3$5496439d@news.astraweb.com> <758a1961-00bc-4b1c-834b-a7deca94d029@googlegroups.com> <579d7141$0$1606$c3e8da3$5496439d@news.astraweb.com> <20160731000133.276c46f0@imp> <579d9d53$0$1619$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de FOmWqYUbnmLI/kY3w2BbSwBhbc1ySwyZra8gev3PCLcA== 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; 'value,': 0.03; 'error:': 0.05; 'none,': 0.05; 'run-time': 0.05; 'subject:code': 0.07; 'cc:addr:python-list': 0.09; 'assigning': 0.09; 'subject:Why': 0.09; 'python': 0.10; 'subject:not': 0.11; 'syntax': 0.13; 'value.': 0.15; '2016': 0.16; 'bugs.': 0.16; 'code).': 0.16; 'did,': 0.16; "didn't,": 0.16; 'editor,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mylist': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'sort()': 0.16; 'subject:allow': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '"",': 0.22; '31,': 0.22; 'latter': 0.22; '(most': 0.24; 'header :In-Reply-To:1': 0.24; 'error': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'looks': 0.29; '(maybe': 0.29; 'subject: [': 0.29; 'useful': 0.33; 'source': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'suddenly': 0.33; 'traceback': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; 'but': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'turn': 0.37; 'say': 0.37; 'sure': 0.39; "didn't": 0.39; 'your': 0.60; 'more': 0.63; '>>>>>': 0.66; 'hints': 0.66; 'realise': 0.66; 'jul': 0.72; '"hey,': 0.84; 'chrisa': 0.84; 'fortunately,': 0.84; 'to:none': 0.91; 'mystery': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=tMsv96n08/AyLT0CghTwMqSYMqr8c0wOSuJvHP3pQ3I=; b=iUuUVh1Bs1LiCcD+vpHZ2Yw+aRGBsNKKCsHjhInKVMbooIoNp6vMs219m2ZNov6JxB yraMpKU1mj+G0lf0to4N23rt2DbQKUQjGRbJwjvc5/GJV/hoSuiqiIzZMVpP6t/WtMn7 OdxxLU4si6g+pkumUceOKh8BTqk2jS+K1eFzJ2XsiV/DR+Nk2XdVIXMn61LVSN2XGWRo Ac4V7xZrM0emF8NxlUoqJSQZxTUcmTrTLKH8fH2F7WIhK0Ssyngp1/djyJMrhmsZjoeA L5Sl3RePvEhv0Q8N2mmlCsm9OAkF1UMCZ4afzPihK7njuoAVJSyuhRf4ZE0GHdrRRQrO Yzew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=tMsv96n08/AyLT0CghTwMqSYMqr8c0wOSuJvHP3pQ3I=; b=Umrre2epvWKrcOEihXGeCDPJOKhZzE/c2B2sBfeflJt2N+a33ZbbA/OFHvYuCDZUy4 uI7nsVtC7el6p6W0mHHm7fnosjuU74kihtWb4caGERxeEmu6S/3ERPFi+K25bYWNRuSw f/NY9OgFx4IATOZd95dH358myOvr8wv6QUKiCB6lsfJjdFFu4PHx/2D6hJR7D5Sudubu J8eiR14k8JBwlbTCbAwPK7++IeMgBsLzZDh1AzngFC7v8tLCDLBWSEYEJETHOdzU25xu sMiakHbaQ5zMIGs4wX+3AF7MX6x39cfWKxNaW3ddMf5pmWy59odgoDmLbPMhH6NLdl6j zAJQ== X-Gm-Message-State: AEkoouvo9Dc9Nnkg6xsHotFQn4QKv+0omstxQ3Vp8+Kn6oXfHbDh9KDAvXg9OZdRvzSiFQ94JLUCqoTCdT7uLQ== X-Received: by 10.28.38.196 with SMTP id m187mr7945244wmm.81.1469948110201; Sat, 30 Jul 2016 23:55:10 -0700 (PDT) In-Reply-To: <579d9d53$0$1619$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <579B1ABB.1070500@rece.vub.ac.be> <579c2095$0$22142$c3e8da3$5496439d@news.astraweb.com> <579cbded$0$1605$c3e8da3$5496439d@news.astraweb.com> <758a1961-00bc-4b1c-834b-a7deca94d029@googlegroups.com> <579d7141$0$1606$c3e8da3$5496439d@news.astraweb.com> <20160731000133.276c46f0@imp> <579d9d53$0$1619$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:112127 On Sun, Jul 31, 2016 at 4:40 PM, Steven D'Aprano wrote: >> While neither is a syntax error, the latter is definitely a run-time >> error: >> >>>>> mylist.sort().reverse() >> Traceback (most recent call last): >> File "", line 1, in >> AttributeError: 'NoneType' object has no attribute 'reverse' > > Hence my description of it as a perplexing source of mystery bugs. How did > mylist suddenly turn into None? > > Well, it didn't, but it sure looks like it did, for those who didn't realise > that sort() is intended to be used *as if* it were a procedure with no > return value. If it *actually* had no return value, Python could give a > more useful error message: > > ProcedureError: list.sort() has no return value Fortunately, a linter can pick this up (maybe even right in your editor, before you move off the line of code). Particularly if type hints are available, a linter can say "Hey, this function always returns None, and you're assigning it to something - that looks wrong". ChrisA