New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Descriptor protocol documentation for super bindings is incorrect #55197
Comments
In 'Doc/reference/datamodel.rst', the 'Invoking Descriptors' documentation specifies the following behavior for super objects: [snip] In the above paragrah, the call: A.__dict__['m'].__get__(obj, A) is incorrect. In reality, the descriptor is invoked via: A.__dict__['m'].__get__(obj, obj.__class__) Loosely speaking, the 'owner' argument is set to the subclass associated with the super object, not the superclass. There is a similar error in the 'Descriptor HowTo Guide' under 'Invoking Descriptors' (Strictly speaking, the specification is inaccurate on some other points. It assumes obj is not a class and doesn't state that the entire mro preceding 'B' is searched for 'm'. But those may be considered simplifications for the sake of brevity) I considered reporting this as a bug in the implementation rather than the specification. But I think the implementation's algorithm is the correct one. In particular, it yields the desired behavior for classmethods In any case, the current behavior has been around for a while (it was the fix for issue bpo-535444, dating back to 2.2) Code demonstrating the current behavior: class Desc(object):
def __get__(self, instance, owner):
return owner
class A(object):
attr = Desc()
class B(A):
pass
class C(B):
pass
instance = C() assert super(B,instance).attr == C #According to the specification, the assertions should be: |
New changeset 50cc60852a76 by Raymond Hettinger in branch '2.7': |
New changeset 3e3c46a3dce8 by Raymond Hettinger in branch '3.1': New changeset 40698c68a32c by Raymond Hettinger in branch '3.2': New changeset 29c8eb206076 by Raymond Hettinger in branch 'default': |
Fixed. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: