Title: Fix data descriptor detection in inspect.getattr_static
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.11
Status: open Resolution:
Dependencies: Superseder: Contradiction in definition of "data descriptor" between (dotted lookup behavior/datamodel documentation) and (inspect lib/descriptor how-to)
View: 26103
Assigned To: Nosy List: davidhalter, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-08-11 16:22 by davidhalter, last changed 2021-12-08 04:22 by rhettinger.

File name Uploaded Description Edit
0001-Fix-data-descriptor-detection-in-inspect.getattr_sta.patch davidhalter, 2017-08-11 16:22 Potential patch that fixes the issue
Messages (4)
msg300170 - (view) Author: David Halter (davidhalter) Date: 2017-08-11 16:22
inspect.getattr_static is currently not identifying data descriptors the right way.

Data descriptors are defined by having a __get__ attribute and at least one of the __set__ and __delete__ attributes.

Implementation detail: Both __delete__ and __get__ set the same slot called tp_descr_set in CPython.

I have attached a patch that fixes the issue IMO.
msg300173 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-08-11 16:36
See also issue26103.
msg407976 - (view) Author: David Halter (davidhalter) Date: 2021-12-07 22:09
This is not a duplicate. It is related to, because __get__ is not required anymore for an object to be a data descriptor. The current code on master (of inspect.getattr_static) still thinks a descriptor has both __get__ and __set__ set.

Since issue #26103 has been fixed, it's now clear that my patch is slightly wrong, but I'm happy to fix that if someone is actually going to review it.
msg407985 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2021-12-07 23:32
Can you give an example of where getattr_static() is not doing what you expect?
Date User Action Args
2021-12-08 04:22:58rhettingersetassignee: rhettinger ->
2021-12-07 23:32:58rhettingersetassignee: rhettinger
type: behavior
components: + Library (Lib)
versions: - Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10
nosy: + rhettinger

messages: + msg407985
2021-12-07 22:09:40davidhaltersetstatus: closed -> open
resolution: duplicate ->
messages: + msg407976

versions: + Python 3.8, Python 3.9, Python 3.10, Python 3.11
2021-11-28 12:18:59iritkatrielsetstatus: open -> closed
superseder: Contradiction in definition of "data descriptor" between (dotted lookup behavior/datamodel documentation) and (inspect lib/descriptor how-to)
resolution: duplicate
stage: resolved
2017-08-11 16:36:24serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg300173
2017-08-11 16:22:11davidhaltercreate