Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110937

Re: Descriptor: class name precedence over instance name

From Ian Kelly <ian.g.kelly@gmail.com>
Newsgroups comp.lang.python
Subject Re: Descriptor: class name precedence over instance name
Date 2016-07-01 22:51 -0600
Message-ID <mailman.10.1467435115.2295.python-list@python.org> (permalink)
References <nl7frv$t48$1@dont-email.me> <CALwzid=h5hn0Qyy15ZhM_xP2BatXSxm9vmRY26wRo9w80OAT1A@mail.gmail.com>

Show all headers | View raw


On Fri, Jul 1, 2016 at 10:27 PM, Veek. M <vek.m1234@gmail.com> 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Descriptor: class name precedence over instance name "Veek. M" <vek.m1234@gmail.com> - 2016-07-02 09:57 +0530
  Re: Descriptor: class name precedence over instance name Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-01 22:51 -0600
  Re: Descriptor: class name precedence over instance name Ben Finney <ben+python@benfinney.id.au> - 2016-07-02 14:52 +1000
    Re: Descriptor: class name precedence over instance name "Veek. M" <vek.m1234@gmail.com> - 2016-07-02 15:04 +0530
      Re: Descriptor: class name precedence over instance name Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-02 07:55 -0600
        Re: Descriptor: class name precedence over instance name "Veek. M" <vek.m1234@gmail.com> - 2016-07-03 20:19 +0530

csiph-web