Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: Case Statements Date: Thu, 17 Mar 2016 22:49:36 +1100 Lines: 72 Message-ID: References: <30502a2e-0bad-4b0f-a1e8-a2b40b0d7ab9@googlegroups.com> <56E928D4.3000701@rece.vub.ac.be> <56E93ADD.9040500@rece.vub.ac.be> <56E961C9.7040008@rece.vub.ac.be> <56E97B60.3060402@rece.vub.ac.be> <56E9A66E.4030905@rece.vub.ac.be> <56e9f7f9$0$1597$c3e8da3$5496439d@news.astraweb.com> <56ea0e4f$0$1585$c3e8da3$5496439d@news.astraweb.com> <56ea4ed2$0$1522$c3e8da3$5496439d@news.astraweb.com> <56ea8c97$0$1607$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de ahEcOSN1RPVufM4A6ofy6w5njNXzlfp47HN73X3hZHaA== 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:209.85.223': 0.03; '"""': 0.05; 'cpython': 0.05; '(b)': 0.07; 'correct.': 0.07; 'expressions': 0.07; 'implements': 0.07; 'cc:addr:python-list': 0.09; 'docs.': 0.09; 'func': 0.09; 'garbage': 0.09; 'implies': 0.09; 'stack,': 0.09; ':-)': 0.12; 'def': 0.13; 'thu,': 0.15; '"is': 0.16; '2016': 0.16; 'correlation': 0.16; 'differs': 0.16; 'equivalence': 0.16; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'func():': 0.16; 'magic': 0.16; 'messy': 0.16; 'oh...': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wording': 0.16; 'wrote:': 0.16; 'alternate': 0.18; 'documented': 0.18; 'creates': 0.18; 'language': 0.19; 'developer': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; 'fix': 0.21; 'meant': 0.22; 'saying': 0.22; '(a)': 0.22; 'decorator': 0.22; 'function,': 0.22; 'pass': 0.22; 'trying': 0.22; '(or': 0.23; 'this:': 0.23; 'plain': 0.24; 'written': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'developers': 0.26; 'rest': 0.26; 'chris': 0.26; 'equivalent': 0.27; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'this.': 0.28; '(it': 0.29; 'behaviour': 0.29; 'equally': 0.29; 'operators': 0.29; 'value)': 0.29; 'objects': 0.29; 'anywhere': 0.30; 'work.': 0.30; 'code': 0.30; '[1]': 0.32; 'language.': 0.32; 'maybe': 0.33; 'useful': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'decorators': 0.33; 'option.': 0.33; 'steven': 0.33; 'case,': 0.34; 'that,': 0.34; 'received:google.com': 0.35; 'ones': 0.35; 'could': 0.35; 'exist': 0.35; 'primarily': 0.35; 'quite': 0.35; 'but': 0.36; 'needed': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'cases': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'thought': 0.37; '(with': 0.38; 'received:209': 0.38; 'does': 0.39; 'still': 0.40; 'collection': 0.60; 'url:3': 0.60; 'your': 0.60; 'leaving': 0.63; 'more': 0.63; 'here:': 0.63; 'interest': 0.64; 'places': 0.64; 'between': 0.65; 'mar': 0.65; 'benefit': 0.66; 'differences': 0.66; 'guaranteed': 0.67; 'analysis': 0.72; 'chrisa': 0.84; 'decorator.': 0.84; 'decorators.': 0.84; 'hard.': 0.84; 'url:datamodel': 0.84; 'url:html#object': 0.84; 'to:none': 0.91; 'careful': 0.91; 'sorry.': 0.91; 'url:reference': 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; bh=z+pyx2seEWxSwHGO/m/OhZoM3ls2KiXsSFy1058Z87I=; b=Yp4wa1VrVM6PrYsvYib/gdOrNqIr4Qe71B89kHLrs5CVeYifVQC5v7SLkzdBhsCLwH /NbOHhah8QzDH92ZeWUG1D402WZNZhLhNodEf3QkxZC8EXxcdBz71S1Q1U0YCV1hBzBo CIn21UN5TFphAsvFpcFBgasRZJ1SxDc3M3foS3p9r4mFIuyyosc4raH1K1CzVpkGzpwe FZqgBl2p4cxE7icrKJYGycfPk/gRvaqtKw32yaW30ktiBKUq+qi+qCuupA8wjz90Z8E1 RCNA3bFmz+8Evq0fDlhmQIPKOqKvbR9g0+A+ZFyGSNArPuZmIX7uXS3x5Wq/w6z33woI ULcQ== 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:date :message-id:subject:from:cc; bh=z+pyx2seEWxSwHGO/m/OhZoM3ls2KiXsSFy1058Z87I=; b=erzPDeIF5DHk9Xz2SOmmbkklPZ0iADpzdJV+WrgKiivUjX2Z48Vz9N0abeWV5UsX4B rTbd+XSyHVwcS7xsWakSTqa7NdOsKeVVOHtJ0yZ23yxx+XyvgM8gDfRfnExgUcgnIJnA AcBSOpvtAaJ9r1VVv2+Irp5PWJVGC9ZZbEA53jUlWGthd1ozzn20lsDvf011VpufcVFp S5EuZ/a7PAT7gIfIqA6IRsbG9/gYehTd4Dt1iCIJ1/xQIrLj8z1qmmp0AX68ZAqdvEYR FUab6Zw0HjLJKZfbh8zSNfGf4B0V1aAWFlOZY28v4ynFfw+iLHPW78WipGioG1jSsy0r S63w== X-Gm-Message-State: AD7BkJK9TZHfbId2d7kv+8I4yA8K3qzNmyOYi9vhzDxmMlFyJpuO6TLQczIHTKZ4cdPvPhMWtkGJ+Wh0CdJAcQ== X-Received: by 10.107.63.139 with SMTP id m133mr8293707ioa.157.1458215376324; Thu, 17 Mar 2016 04:49:36 -0700 (PDT) In-Reply-To: <56ea8c97$0$1607$c3e8da3$5496439d@news.astraweb.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 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:105086 On Thu, Mar 17, 2016 at 9:53 PM, Steven D'Aprano wrote: > On Thu, 17 Mar 2016 05:48 pm, Chris Angelico wrote: > >> Okay. Let's try this. > [...] >> Decorators work. Now let's try NOT using decorators. > > You are still using a decorator. You're just not using @ decorator syntax. Oops, sorry. That was sloppy wording on my part. What I meant was "decorator syntax". The rest of your analysis was equally correct. > But we can fix it like this: > > def x(self): > print("Getting x") > return 42 > x = property(x) > def y(self, value): > print("Setting x to", value) > x = x.setter(y) Oh... I thought x.setter() needed the name to be the same. Okay, in that case it's not so hard. Doesn't need the messy temporaries of the other option. >> This is how CPython implements this (it evaluates the decoration >> expressions first, leaving them on the stack, then creates the >> function, then calls the decorators), but I don't see anywhere that >> this is guaranteed in the docs either - the only way I know this is >> current behaviour is from trying it (with dis.dis). The documented >> equivalence simply doesn't work. > > It does work. You just have to be careful to not garbage collect objects > before you can use them :-) The "documented equivalence" is what's written here: https://docs.python.org/3/reference/compound_stmts.html#function """ For example, the following code @f1(arg) @f2 def func(): pass is equivalent to def func(): pass func = f1(arg)(f2(func)) """ Saying "is equivalent to" implies a correlation that, in this case, is imperfect. But to be fair, these kinds of edge cases are (a) only of interest to language developers and the curious, and (b) exist in quite a few places in the language. The correspondence between operators and magic methods [1] has the same flaw; saying that x