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.)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…