Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #105070
| Path | csiph.com!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 17:48:58 +1100 |
| Lines | 86 |
| Message-ID | <mailman.257.1458197342.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> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de s7x5W/7W60nEpCLK0EgXswK1KnMt7uAj1Vr7HFYMyngw== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'expressions': 0.07; 'implements': 0.07; 'cc:addr:python-list': 0.09; '@property': 0.09; 'situation.': 0.09; 'stack,': 0.09; 'def': 0.13; 'thu,': 0.15; '2016': 0.16; 'equivalence': 0.16; 'evaluates': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'documented': 0.18; 'creates': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'first,': 0.20; '"",': 0.22; 'decorator': 0.22; 'function,': 0.22; 'object.': 0.22; 'trying': 0.22; 'second': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'this.': 0.28; '(it': 0.29; 'behaviour': 0.29; 'value)': 0.29; 'anywhere': 0.30; 'work.': 0.30; 'getting': 0.33; 'changed': 0.33; 'class': 0.33; "d'aprano": 0.33; 'decorators': 0.33; 'steven': 0.33; 'traceback': 0.33; 'similar': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'setting': 0.37; 'received:209.85.213': 0.37; '(with': 0.38; 'received:209': 0.38; 'anything': 0.38; 'here.': 0.62; 'leaving': 0.63; 'mar': 0.65; 'here': 0.66; 'guaranteed': 0.67; 'brand': 0.75; "'def'": 0.84; 'chrisa': 0.84; 'decorator:': 0.84; 'decorators.': 0.84; 'underneath': 0.84; 'x...': 0.84; 'to:none': 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=Ll9h8smMF3AwCUCRAkO6iZF4hTmoEg5hhQjCdtuI+k8=; b=EIzC7LQW3Z8gHIcbkb5mcpEsA8eLBGjodxojFI1DsX9+Rwhqj0Egi8tNCEbX1tVJ6b HFXWOr2QvI5RAAodEY1Bq6VkSsg+B3xA4h0ElIdXbH3XuPzBgLquZt7CJT00HEZXDIh2 suCRsS4A/WPACaycwmkXo4nlw/fadFGuWjiOmFS982lfEdlHgk7RNeARBWIhjC41oJGM qQYqg2HY8QHbtN/wahBYBpf+vry6ZRJAO5+wxxIGBntkg0L84sakGi3q4S/iugHXv57Z 79rwY0UTdG0Agdms8ae2IboiKuKvyVVF6zy4p75K452goK7oQPyndAuRDus9s8b+npdK uCWw== |
| 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=Ll9h8smMF3AwCUCRAkO6iZF4hTmoEg5hhQjCdtuI+k8=; b=B0HwNWKLX54c5ULZPnmhVpSGeV1DoM1gckXI6PH6XlrQ4hXddWdlGRGIg0Po2V7H4Z oqn8ywoByCZxRJ3fhcy/FeDG2oxHpQoZK4S92zwqjtbriJfhcqN0g0wWNXaNtYcEdram PzCrLB318bDvYADPc52baRDIABed3dtdFK9KgBOLGtm7i0LLacJHMtIaYqAJb0SZULNl FAyNSa0IXr32VoKYAJPnSs3I/sfuQsRKWKv4vV0QP4CvsiUksflLzlj21Q7YR3+WgXYC gksLfgb5R18qY2aUBmV+Zhwqo1cz76V60MoLxbCnGqKxrcLiRx46AVGdtAsvlXmjvqs6 8IcA== |
| X-Gm-Message-State | AD7BkJI+jlP5sYGOu6zyNj4sGPWGgQpmQLdqFilusuTA2bg6i85rqdu2T8NYGwx7Y4yn+d4oxWgoUA/57R9KdA== |
| X-Received | by 10.50.43.226 with SMTP id z2mr5702283igl.94.1458197338929; Wed, 16 Mar 2016 23:48:58 -0700 (PDT) |
| In-Reply-To | <56ea4ed2$0$1522$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:105070 |
Show key headers only | View raw
On Thu, Mar 17, 2016 at 5:29 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> I don't think that property is a similar situation. I think what happens
> here is that the first call to property sets:
>
> # @property def x...
> x = property(x)
>
> Then the second decorator does:
>
> # @x.setter def x...
> x = x.setter(x)
>
> which replaces x with a brand new property object.
Okay. Let's try this.
>>> class Demo:
... @property
... def x(self):
... print("Getting x")
... return 42
... @x.setter
... def x(self, value):
... print("Setting x to", value)
...
>>> d = Demo()
>>> d.x
Getting x
42
>>> d.x = 1
Setting x to 1
Decorators work. Now let's try NOT using decorators.
>>> class Demo:
... def x(self):
... print("Getting x")
... return 42
... x = property(x)
... def x(self, value):
... print("Setting x to", value)
... x = x.setter(x)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 8, in Demo
AttributeError: 'function' object has no attribute 'setter'
Since the 'def' line bound the undecorated function to the name 'x',
the decoration underneath *fails*. The only way this could work would
be with a temporary name for either the new function or the decorator:
>>> class Demo:
... def x(self):
... print("Getting x")
... return 42
... x = property(x)
... decorator = x.setter
... def x(self, value):
... print("Setting x to", value)
... x = decorator(x)
... del decorator
...
>>> d = Demo()
>>> d.x
Getting x
42
>>> d.x = 1
Setting x to 1
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.
Note, by the way, that I am not in any way criticising the *behaviour*
here. I don't think anything needs to be changed as regards
functionality. And it's not even that big an issue as regards
documentation. It's mainly just an esoteric curiosity.
ChrisA
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