msg258168 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2016-01-13 20:56 |
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. Data descriptors have both a __get__ and a __set__ attribute...""" if isclass(object) or ismethod(object) or isfunction(object): # mutual exclusion return False tp = type(object) return hasattr(tp, "__set__") and hasattr(tp, "__get__") I'm willing to sign a contributor release and fix myself. |
|
|
msg295212 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-06-05 20:43 |
Bumping this - I intend to work on this next, if no objections. |
|
|
msg295243 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-06-06 07:13 |
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. |
|
|
msg295287 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-06-06 18:13 |
Added news, working on tests |
|
|
msg295288 - (view) |
Author: Mariatta (Mariatta) *  |
Date: 2017-06-06 18:16 |
Please also add yourself to Misc/ACKS. |
|
|
msg295307 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-06-06 22:27 |
> Please also add yourself to Misc/ACKS. Done! |
|
|
msg295378 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-06-08 03:49 |
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? |
|
|
msg301206 - (view) |
Author: Aaron Hall (Aaron Hall) * |
Date: 2017-09-04 04:11 |
Serhiy, Not sure what else needs to be done to wrap this up. All checks are passing on the pull request. Thoughts? |
|
|
msg302721 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2017-09-21 20:45 |
The only question is remained -- should *data descriptors* be *descriptors*? I.e. is the __get__ method required for data descriptors? |
|
|
msg308078 - (view) |
Author: Lior Cohen (chnlior) |
Date: 2017-12-11 23:24 |
Joining @Serhiy Storchaka last question. Is the __get__ method existance is a must be a data descriptor? According to the C implementation in descrobject.h ``` #define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL) #endif ``` the answer is No. Does this C code reflect the true definition? |
|
|
msg317211 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2018-05-20 23:46 |
New changeset 4054b172ab59054715a2aaf4979bd84ac23e3ada by Serhiy Storchaka (Aaron Hall, MBA) in branch 'master': bpo-26103: Fix inspect.isdatadescriptor() and a data descriptor definition. (GH-1959) https://github.com/python/cpython/commit/4054b172ab59054715a2aaf4979bd84ac23e3ada |
|
|
msg338426 - (view) |
Author: Cheryl Sabella (cheryl.sabella) *  |
Date: 2019-03-20 00:19 |
It looks like this issue can be closed now that it's merged? |
|
|