Skip to content
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

bpo-40170: Convert PyDescr_IsData macro to C function #24535

Merged
merged 5 commits into from
Feb 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/c-api/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ found in the dictionary of type objects.

.. c:function:: int PyDescr_IsData(PyObject *descr)

Return true if the descriptor objects *descr* describes a data attribute, or
false if it describes a method. *descr* must be a descriptor object; there is
Return non-zero if the descriptor objects *descr* describes a data attribute, or
``0`` if it describes a method. *descr* must be a descriptor object; there is
no error checking.


Expand Down
2 changes: 1 addition & 1 deletion Include/descrobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ PyAPI_FUNC(PyObject *) PyDescr_NewGetSet(PyTypeObject *,
#ifndef Py_LIMITED_API
PyAPI_FUNC(PyObject *) PyDescr_NewWrapper(PyTypeObject *,
struct wrapperbase *, void *);
#define PyDescr_IsData(d) (Py_TYPE(d)->tp_descr_set != NULL)
PyAPI_FUNC(int) PyDescr_IsData(PyObject *);
#endif

PyAPI_FUNC(PyObject *) PyDictProxy_New(PyObject *);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Convert :c:func:`PyDescr_IsData` macro to a function to hide implementation
details: The macro accessed :c:member:`PyTypeObject.tp_descr_set` directly.
Patch by Erlend E. Aasland.
5 changes: 5 additions & 0 deletions Objects/descrobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,11 @@ PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *base, void *wrapped)
return (PyObject *)descr;
}

int
PyDescr_IsData(PyObject *ob)
{
return Py_TYPE(ob)->tp_descr_set != NULL;
}

/* --- mappingproxy: read-only proxy for mappings --- */

Expand Down