Look up an attribute from an instance

后端 未结 1 925
清歌不尽
清歌不尽 2020-12-20 05:08

From Python in a Nutshell

Getting an attribute from an instance

When you use the syntax x.name to refer to

相关标签:
1条回答
  • 2020-12-20 06:07

    Are step 1 and the first part of step 3 the same? If yes, why the same step appear twice?

    Step 1 requires both __get__ and __set__ (although actually, either __set__ or __delete__ along with __get__ would trigger it). Step 3 happens unconditionally if the attribute isn't found through steps 1 or 2.

    Do they both happen "when name is found in C (or in one of C’s ancestor classes) as the name of an overriding descriptor v"?

    No. An "overriding descriptor" triggers step 1; another kind of descriptor or a non-descriptor will only be considered in step 3. (The official Python docs don't use the term "overriding descriptor"; they refer to a descriptor with __set__ or __delete__ as a "data descriptor", and if a data descriptor has __get__, the __get__ will take priority over an object found in an instance dict.)

    0 讨论(0)
提交回复
热议问题