Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105086
| Path | csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Case Statements |
| Date | Thu, 17 Mar 2016 22:49:36 +1100 |
| Lines | 72 |
| Message-ID | <mailman.268.1458215384.12893.python-list@python.org> (permalink) |
| References | <f30500db-19cb-4de8-81f1-6eb77c28b3b4@googlegroups.com> <30502a2e-0bad-4b0f-a1e8-a2b40b0d7ab9@googlegroups.com> <mailman.181.1458102409.12893.python-list@python.org> <ncb4e0$op1$1@dont-email.me> <ncb6jk$rrm$1@ger.gmane.org> <56E928D4.3000701@rece.vub.ac.be> <ncbac2$qtk$1@ger.gmane.org> <56E93ADD.9040500@rece.vub.ac.be> <ncbeq6$vq$1@ger.gmane.org> <56E961C9.7040008@rece.vub.ac.be> <ncbp2b$ge6$3@ger.gmane.org> <56E97B60.3060402@rece.vub.ac.be> <ncc4tb$6kj$1@ger.gmane.org> <56E9A66E.4030905@rece.vub.ac.be> <mailman.253.1458170061.12893.python-list@python.org> <56e9f7f9$0$1597$c3e8da3$5496439d@news.astraweb.com> <mailman.254.1458174695.12893.python-list@python.org> <56ea0e4f$0$1585$c3e8da3$5496439d@news.astraweb.com> <dkuujrFcplnU1@mid.individual.net> <56ea4ed2$0$1522$c3e8da3$5496439d@news.astraweb.com> <mailman.257.1458197342.12893.python-list@python.org> <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 | <rosuav@gmail.com> |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:105086 |
Show key headers only | View raw
On Thu, Mar 17, 2016 at 9:53 PM, Steven D'Aprano <steve@pearwood.info> 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<y
calls x.__lt__(y) is not entirely accurate, but is much more useful to
people than x.__class__.__lt__(x, y) (or is it "type(x).__lt__(x, y)"?
I can never remember what the differences are between type() and
__class__), so it's correct to use that in the docs. Maybe there needs
to be a collection of "language developer esoteria", primarily for the
benefit of alternate implementations? It could enumerate the ways in
which CPython differs from the plain and simple docs, and say which
ones are important language features and which are implementation
details.
ChrisA
[1] https://docs.python.org/3/reference/datamodel.html#object.__lt__
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Case Statements jj0gen0info@gmail.com - 2016-03-15 13:46 -0700
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 23:11 +0000
Re: Case Statements jj0gen0info@gmail.com - 2016-03-15 16:47 -0700
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-15 23:58 +0000
Re: Case Statements BartC <bc@freeuk.com> - 2016-03-16 00:51 +0000
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 01:05 +0000
Re: Case Statements jj0gen0info@gmail.com - 2016-03-15 18:55 -0700
Re: Case Statements "Mario R. Osorio" <nimbiotics@gmail.com> - 2016-03-15 21:06 -0700
Re: Case Statements BartC <bc@freeuk.com> - 2016-03-16 10:34 +0000
Re: Case Statements Steven D'Aprano <steve@pearwood.info> - 2016-03-16 23:56 +1100
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 04:26 +0000
Re: Case Statements Christian Gollwitzer <auriocus@gmx.de> - 2016-03-16 09:13 +0100
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 08:47 +0000
Re: Case Statements Marko Rauhamaa <marko@pacujo.net> - 2016-03-16 11:16 +0200
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-16 10:35 +0100
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 09:51 +0000
Re: Case Statements BartC <bc@freeuk.com> - 2016-03-16 19:41 +0000
Re: Case Statements BartC <bc@freeuk.com> - 2016-03-16 22:30 +0000
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-16 11:52 +0100
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 11:07 +0000
Re: Case Statements BartC <bc@freeuk.com> - 2016-03-16 11:16 +0000
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 11:33 +0000
Re: Case Statements Marko Rauhamaa <marko@pacujo.net> - 2016-03-16 14:21 +0200
Re: Case Statements BartC <bc@freeuk.com> - 2016-03-16 12:53 +0000
Re: Case Statements Marko Rauhamaa <marko@pacujo.net> - 2016-03-16 16:31 +0200
Re: Case Statements BartC <bc@freeuk.com> - 2016-03-16 15:00 +0000
Re: Case Statements Marko Rauhamaa <marko@pacujo.net> - 2016-03-16 19:07 +0200
Re: Case Statements Rustom Mody <rustompmody@gmail.com> - 2016-03-20 01:01 -0700
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-20 08:29 +0000
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-16 14:38 +0100
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 14:02 +0000
Re: Case Statements Marko Rauhamaa <marko@pacujo.net> - 2016-03-16 21:27 +0200
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-17 09:22 +0100
Re: Case Statements Marko Rauhamaa <marko@pacujo.net> - 2016-03-17 10:57 +0200
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-17 10:12 +0100
Re: Case Statements Steven D'Aprano <steve@pearwood.info> - 2016-03-17 11:19 +1100
Re: Case Statements Steven D'Aprano <steve@pearwood.info> - 2016-03-17 12:54 +1100
Re: Case Statements Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-17 18:45 +1300
Re: Case Statements Chris Angelico <rosuav@gmail.com> - 2016-03-17 17:30 +1100
Re: Case Statements Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-18 18:59 +1300
Re: Case Statements Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-17 17:29 +1100
Re: Case Statements Chris Angelico <rosuav@gmail.com> - 2016-03-17 17:48 +1100
Re: Case Statements Steven D'Aprano <steve@pearwood.info> - 2016-03-17 21:53 +1100
Re: Case Statements Chris Angelico <rosuav@gmail.com> - 2016-03-17 22:49 +1100
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-17 10:23 +0100
Re: Case Statements Chris Angelico <rosuav@gmail.com> - 2016-03-17 20:55 +1100
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-17 09:36 +0100
Re: Case Statements Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2016-03-17 09:38 +0100
Re: Case Statements l0r0m0a0i0l@gmail.com - 2016-03-16 06:15 -0700
Re: Case Statements Steven D'Aprano <steve@pearwood.info> - 2016-03-17 00:27 +1100
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 14:00 +0000
Re: Case Statements Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-16 13:59 +0000
Re: Case Statements l0r0m0a0i0l@gmail.com - 2016-03-16 07:21 -0700
Re: Case Statements Marko Rauhamaa <marko@pacujo.net> - 2016-03-16 16:33 +0200
csiph-web