-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
Contradiction in definition of "data descriptor" between (dotted lookup behavior/datamodel documentation) and (inspect lib/descriptor how-to) #70291
Comments
Based on the data-model documentation (https://docs.python.org/2/reference/datamodel.html#invoking-descriptors) and the dotted lookup behavior, the follow definitions are correct: "If the descriptor defines __set__() and/or __delete__(), it is a data descriptor; if it defines neither, it is a non-data descriptor." def has_data_descriptor_attrs(obj):
return set(['__set__', '__delete__']) & set(dir(obj))
def is_data_descriptor(obj):
return bool(has_data_descriptor_attrs(obj)) However, the inspect module has the following, which is also reflected in the descriptor how-to (https://docs.python.org/2/howto/descriptor.html#descriptor-protocol): "If an object defines both __get__() and __set__(), it is considered a data descriptor." def isdatadescriptor(object):
"""Return true if the object is a data descriptor.
I'm willing to sign a contributor release and fix myself. |
Bumping this - I intend to work on this next, if no objections. |
This isn't just a documentation issue since it fixes inspect.isdatadescriptor(). I confirm that the new implementation better matches the C code. LGTM, but needed tests for inspect.isdatadescriptor() and a Misc/NEWS entry. |
Added news, working on tests |
Please also add yourself to Misc/ACKS. |
Done! |
I tweaked the docs a little more this morning, but I believe I am done making any further changes unless so requested. This issue doesn't say it's assigned to anyone. Is there anything else that needs to happen here? |
Serhiy, Not sure what else needs to be done to wrap this up. All checks are passing on the pull request. Thoughts? |
The only question is remained -- should *data descriptors* be *descriptors*? I.e. is the __get__ method required for data descriptors? |
Joining @serhiy Storchaka last question. According to the C implementation in descrobject.h
the answer is No. |
It looks like this issue can be closed now that it's merged? |
I suspect that this issue was resolved in the wrong direction. It is meaningless and not useful to define something as a "data descriptor" that does not have a The reason I'm not sure whether this is important enough to file a new issue and fix. The main case where I can see it might cause confusion is that e.g. if |
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: