Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 5 additions & 5 deletions Doc/c-api/structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,11 @@ definition with the same method name.
handles use of the :keyword:`del` statement on that attribute more correctly
than :c:macro:`T_OBJECT`.

:attr:`flags` can be ``0`` for write and read access or :c:macro:`READONLY` for
read-only access. Using :c:macro:`T_STRING` for :attr:`type` implies
:c:macro:`READONLY`. :c:macro:`T_STRING` data is interpreted as UTF-8.
Only :c:macro:`T_OBJECT` and :c:macro:`T_OBJECT_EX`
members can be deleted. (They are set to *NULL*).
:attr:`flags` can be ``0`` for write and read access (also represented by the
:c:macro:`PY_READWRITE`) or or :c:macro:`PY_READONLY` for read-only access.
Using :c:macro:`T_STRING` for :attr:`type` implies :c:macro:`PY_READONLY`.
:c:macro:`T_STRING` data is interpreted as UTF-8. Only :c:macro:`T_OBJECT`
and :c:macro:`T_OBJECT_EX` members can be deleted. (They are set to *NULL*).


.. c:type:: PyGetSetDef
Expand Down
29 changes: 18 additions & 11 deletions Doc/extending/newtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -282,23 +282,30 @@ store flags which control how the attribute can be accessed.
The following flag constants are defined in :file:`structmember.h`; they may be
combined using bitwise-OR.

+---------------------------+----------------------------------------------+
| Constant | Meaning |
+===========================+==============================================+
| :const:`READONLY` | Never writable. |
+---------------------------+----------------------------------------------+
| :const:`READ_RESTRICTED` | Not readable in restricted mode. |
+---------------------------+----------------------------------------------+
| :const:`WRITE_RESTRICTED` | Not writable in restricted mode. |
+---------------------------+----------------------------------------------+
| :const:`RESTRICTED` | Not readable or writable in restricted mode. |
+---------------------------+----------------------------------------------+
+------------------------------+----------------------------------------------+---------------------------+
| Constant | Meaning | Former Constant |
+==============================+==============================================+===========================+
| :const:`PY_READWRITE` | Writable. | 0 |
+------------------------------+----------------------------------------------+---------------------------+
| :const:`PY_READONLY` | Never writable. | :const:`READONLY` |
+------------------------------+----------------------------------------------+---------------------------+
| :const:`PY_READ_RESTRICTED` | Not readable in restricted mode. | :const:`READ_RESTRICTED` |
+------------------------------+----------------------------------------------+---------------------------+
| :const:`PY_WRITE_RESTRICTED` | Not writable in restricted mode. | :const:`WRITE_RESTRICTED` |
+------------------------------+----------------------------------------------+---------------------------+
| :const:`PY_RESTRICTED` | Not readable or writable in restricted mode. | :const:`RESTRICTED` |
+------------------------------+----------------------------------------------+---------------------------+

.. index::
single: READONLY
single: READ_RESTRICTED
single: WRITE_RESTRICTED
single: RESTRICTED
single: PY_READWRITE
single: PY_READONLY
single: PY_READ_RESTRICTED
single: PY_WRITE_RESTRICTED
single: PY_RESTRICTED

An interesting advantage of using the :c:member:`~PyTypeObject.tp_members` table to build
descriptors that are used at runtime is that any attribute defined this way can
Expand Down
18 changes: 13 additions & 5 deletions Include/structmember.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ typedef struct PyMemberDef {


/* Flags */
#define READONLY 1
#define READ_RESTRICTED 2
#define PY_WRITE_RESTRICTED 4
#define RESTRICTED (READ_RESTRICTED | PY_WRITE_RESTRICTED)

enum {
PY_READWRITE = 0,
PY_READONLY = 1,
PY_READ_RESTRICTED = 2,
PY_WRITE_RESTRICTED = 4,
PY_RESTRICTED = (PY_READ_RESTRICTED | PY_WRITE_RESTRICTED),

// Flags for backward-compatibility
READONLY Py_DEPRECATED(3.8) = PY_READONLY,
READWRITE Py_DEPRECATED(3.8) = PY_READWRITE,
READ_RESTRICTED Py_DEPRECATED(3.8) = PY_READ_RESTRICTED,
RESTRICTED Py_DEPRECATED(3.8) = PY_RESTRICTED
};

/* Current API, use this */
PyAPI_FUNC(PyObject *) PyMember_GetOne(const char *, struct PyMemberDef *);
Expand Down