Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Descriptor: class name precedence over instance name Date: Fri, 1 Jul 2016 22:51:08 -0600 Lines: 51 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de uLONJuZughj8z0qXbHOq/A0mIqaZoQ/FRkellVx/N2iQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'attributes': 0.07; 'defines': 0.07; 'descriptor': 0.09; 'instances.': 0.09; 'likewise': 0.09; 'precedence': 0.09; 'stored': 0.10; 'def': 0.13; '2016': 0.16; 'attribute,': 0.16; 'attributes.': 0.16; 'descriptor"': 0.16; 'descriptor,': 0.16; 'descriptors': 0.16; 'descriptors.': 0.16; 'foo()': 0.16; 'foo.': 0.16; 'inserting': 0.16; 'non-data': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:class': 0.16; 'subject:instance': 0.16; 'underscore.': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'instance,': 0.18; 'first,': 0.20; 'parameter': 0.22; 'trying': 0.22; 'slightly': 0.23; 'header:In-Reply-To:1': 0.24; 'skip:- 40': 0.25; 'example': 0.26; 'sense': 0.26; 'checking': 0.27; 'fri,': 0.27; 'not.': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'classes': 0.30; 'class.': 0.30; 'checked': 0.31; 'skip:_ 10': 0.32; 'changed': 0.33; 'class': 0.33; 'foo': 0.33; 'previous': 0.34; 'skip:- 50': 0.35; 'received:google.com': 0.35; 'done': 0.35; 'instance': 0.35; 'asking': 0.35; "isn't": 0.35; 'depends': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'say': 0.37; 'itself': 0.38; 'why': 0.39; 'data': 0.39; 'does': 0.39; 'takes': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'leading': 0.61; 'back': 0.62; 'different': 0.63; 'here': 0.66; 'jul': 0.72; 'special': 0.73; 'subject:over': 0.84; 'to:name:python': 0.84 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:to; bh=YFtnVcN6Z7WiibT6g7nPpmRrV7zOPlSmyBCo+tNlTds=; b=A1ONOBe/oPh0AuLdswGnbXHEdl9201MjygzUP7WVdgOWdBTV5kPCxtv1yBXKED72ls /W5Rg6exY3RdThBGaJ9KzTZKZ4ZS63YfWQSlS1Zi6b1wf5aT+xhyGq2aodYsEIH7CX2G Z1dYQc50BIgsBNLp9Ya4c9xk6+YT7Czx3ebhn9J1Oh8b0GZVslSFToxLU9ty1am/7R/x ZnrZ5fEm3bR6/5G9xJOenyb4fW5NnO5NdzCtfqE9mXGyEC7T5vgmtI1+SS2x6tjR1NHs vpPmfKLJH22f/U2cJiSNelChYGEdxnlDhtKYuHRatHDQ4j9w5Fd3RjawIB4o9Qu0cyvJ JHqw== 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:to; bh=YFtnVcN6Z7WiibT6g7nPpmRrV7zOPlSmyBCo+tNlTds=; b=Cxk/TuV7/md0+8pBxQMcbks8mBSDUnj6yd1uXstgboL1xPUThTDKuhv4Z/VJ6hfbO8 2Y6bz21rUYxyNoaGAKTqlkBKa8YGF2mKUDcy2/3CtFQatecYOQDc5D6Qj9LRjy6j4G9O SJwGmyB/aIMUwZF0Whvw0FrjPsYdZkvlewSTCLyEm/zXFLjyydERxj0iOgWrmafF4BNx qS/wl1QDnl4cM+JNeDlXNEihMB2phCcUIr7QvKtr9nTfKB7zC2WhwP7EQJSZGSvqElgH h5XDXwDLzTgj7FVGs8I7WzC5Wy6FAu8LTSkB1XgsOnU+eWy7J5kmdcJO5zTqMJur1EE5 qX8Q== X-Gm-Message-State: ALyK8tI7UWX+4cQAYsatf4QBGT+dZHNAIswbxZ728PiqfmLquGO7PLGcuqUM2qOJ/xqhAeBcCIPAgxUUJOm77w== X-Received: by 10.157.9.41 with SMTP id 38mr1122681otp.190.1467435107859; Fri, 01 Jul 2016 21:51:47 -0700 (PDT) In-Reply-To: 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: Xref: csiph.com comp.lang.python:110937 On Fri, Jul 1, 2016 at 10:27 PM, Veek. M wrote: > Trying to make sense of this para: > > -------------------------------------------------- > Also, the attribute name used by the class to hold a descriptor takes > prece- dence over attributes stored on instances. > > In the previous example, > this is why the descriptor object takes a name parameter and why the > name is changed slightly by inserting a leading underscore. In order > for the descriptor to store a value on the instance, it has to pick a > name that is different than that being used by the descriptor itself > --------------------------------------------- > Under normal circumstances, when I do an attribute lookup: > x = Foo() > x.a > he will first check 'x' then Foo. > > Is he say that Descriptors are a special case where Foo is checked > first, It depends whether it's a "data descriptor" or not. A data descriptor is one that defines at least one of __set__ or __delete__, not just __get__. Data descriptors take precendence over instance attributes. Instance attributes take precedence over non-data descriptors. > then what - Base classes..? Checking base classes is part of checking the class. If a base class has a data descriptor, that will likewise take precedence over the instance attribute, which will likewise take precedence over non-data descriptors in the base class. > or does he hop back to look in the > instance? How is C3 Linearization altered? It's not. > Additionally, > class Foo: > def __init__(self, name, value): > self.name = name > > cannot be done because > x = Foo('bar', 10) > > x.bar will..? attribute in class takes precedence.. great, isn't that > what we want? I don't understand what you're asking here or what this example has to do with descriptors.