Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104718
| Path | csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.python |
| Subject | Re: Descriptors vs Property |
| Date | Sat, 12 Mar 2016 18:13:50 +0100 |
| Organization | PointedEars Software (PES) |
| Lines | 43 |
| Message-ID | <6979634.CGS0JZJfMg@PointedEars.de> (permalink) |
| References | <nc0b1u$ckq$1@dont-email.me> <nc0c8o$fvn$1@dont-email.me> |
| Reply-To | Thomas 'PointedEars' Lahn <usenet@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1457802830 32412 eJwFwYEBwCAIA7CXEGjRcybS/09YguBiVxJMCGItg6TtMWnFPl59Uw9R4hPaXIOJj9dO7B8XRRET (12 Mar 2016 17:13:50 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Sat, 12 Mar 2016 17:13:50 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwNybEBACEIBLCVEOHAcR4P9h/hbdLENxZuGBzm48OlKMqZc8XywcF060RGNt8XSh1tvJBPdlSyTwm4dan8b2EV9w== |
| Cancel-Lock | sha1:6wkOdCtDCN8+dw3obnQPagIINsc= |
| X-NNTP-Posting-Host | eJwFwYEBwCAIA7CXBGll5wCu/59ggk3jnCAYEORuf3nV5MlZeTO8ZE3JsYTw2DY9on1dvPcBIF8RgA== |
| Xref | csiph.com comp.lang.python:104718 |
Show key headers only | View raw
Veek. M wrote:
> Veek. M wrote:
>> class TypedProperty(object):
>> def __init__(self,name,type,default=None):
>> self.name = "_" + name
>> self.type = type
>> self.default = default if default else type()
>>
>> def __get__(self,instance,cls):
>> return getattr(instance,self.name,self.default)
>> […]
>> class Foo(object):
>> name = TypedProperty("name",str)
>> num = TypedProperty("num",int,42)
>> […]
>> When you do f.name you are actually doing:
>>
>> f.name.__get__(self, instance, cls)
Correct.
>> What the heck??
> As in, why is he passing instance, cls and who is populating those vars?
RTFM:
<https://docs.python.org/3/reference/datamodel.html?highlight=__get__#implementing-descriptors>
> When you do f.name you just have self to pass into
> name.__whatever__(self)
No.
> I haven't read the descriptor protocol as yet.
You should. You should also trim your quotations to the relevant minimum,
and post using your real name.
--
PointedEars
Twitter: @PointedEars2
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-12 11:29 +0530
Re: Descriptors vs Property Chris Angelico <rosuav@gmail.com> - 2016-03-12 17:05 +1100
Re: Descriptors vs Property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-11 23:12 -0700
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-12 11:54 +0530
Re: Descriptors vs Property Chris Angelico <rosuav@gmail.com> - 2016-03-12 17:35 +1100
Re: Descriptors vs Property Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-11 23:37 -0700
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-12 11:50 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-12 18:13 +0100
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-13 12:48 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-13 10:25 +0100
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-13 15:26 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-13 11:35 +0100
Re: Descriptors vs Property "Veek. M" <vek.m1234@gmail.com> - 2016-03-13 18:50 +0530
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-13 19:15 +0100
Re: Descriptors vs Property Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 15:34 +0000
Re: Descriptors vs Property Rustom Mody <rustompmody@gmail.com> - 2016-03-14 10:16 -0700
Re: Descriptors vs Property Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-16 01:53 +0100
Re: Descriptors vs Property Ethan Furman <ethan@stoneleaf.us> - 2016-03-16 08:15 -0700
csiph-web