Skip to content
Open
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
63 changes: 63 additions & 0 deletions Doc/c-api/dict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ Dictionary objects
enforces read-only behavior. This is normally used to create a view to
prevent modification of the dictionary for non-dynamic class types.

The first argument can be a :class:`dict`, a :class:`frozendict`, or a
mapping.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:var:: PyTypeObject PyDictProxy_Type

Expand All @@ -68,15 +74,25 @@ Dictionary objects
*key*, return ``1``, otherwise return ``0``. On error, return ``-1``.
This is equivalent to the Python expression ``key in p``.

The first argument can be a :class:`dict` or a :class:`frozendict`.

.. versionchanged:: next
Also accept :class:`frozendict`.


.. c:function:: int PyDict_ContainsString(PyObject *p, const char *key)

This is the same as :c:func:`PyDict_Contains`, but *key* is specified as a
:c:expr:`const char*` UTF-8 encoded bytes string, rather than a
:c:expr:`PyObject*`.

The first argument can be a :class:`dict` or a :class:`frozendict`.

.. versionadded:: 3.13

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: PyObject* PyDict_Copy(PyObject *p)

Expand Down Expand Up @@ -122,8 +138,13 @@ Dictionary objects
* If the key is missing, set *\*result* to ``NULL`` and return ``0``.
* On error, raise an exception and return ``-1``.

The first argument can be a :class:`dict` or a :class:`frozendict`.

.. versionadded:: 3.13

.. versionchanged:: next
Accept also :class:`frozendict`.

See also the :c:func:`PyObject_GetItem` function.


Expand All @@ -133,6 +154,8 @@ Dictionary objects
has a key *key*. Return ``NULL`` if the key *key* is missing *without*
setting an exception.

The first argument can be a :class:`dict` or a :class:`frozendict`.

.. note::

Exceptions that occur while this calls :meth:`~object.__hash__` and
Expand All @@ -143,6 +166,9 @@ Dictionary objects
Calling this API without an :term:`attached thread state` had been allowed for historical
reason. It is no longer allowed.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: PyObject* PyDict_GetItemWithError(PyObject *p, PyObject *key)

Expand All @@ -151,6 +177,9 @@ Dictionary objects
occurred. Return ``NULL`` **without** an exception set if the key
wasn't present.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: PyObject* PyDict_GetItemString(PyObject *p, const char *key)

Expand All @@ -166,6 +195,9 @@ Dictionary objects
Prefer using the :c:func:`PyDict_GetItemWithError` function with your own
:c:func:`PyUnicode_FromString` *key* instead.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: int PyDict_GetItemStringRef(PyObject *p, const char *key, PyObject **result)

Expand All @@ -175,6 +207,9 @@ Dictionary objects

.. versionadded:: 3.13

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *defaultobj)

Expand Down Expand Up @@ -238,17 +273,32 @@ Dictionary objects

Return a :c:type:`PyListObject` containing all the items from the dictionary.

The first argument can be a :class:`dict` or a :class:`frozendict`.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: PyObject* PyDict_Keys(PyObject *p)

Return a :c:type:`PyListObject` containing all the keys from the dictionary.

The first argument can be a :class:`dict` or a :class:`frozendict`.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: PyObject* PyDict_Values(PyObject *p)

Return a :c:type:`PyListObject` containing all the values from the dictionary
*p*.

The first argument can be a :class:`dict` or a :class:`frozendict`.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: Py_ssize_t PyDict_Size(PyObject *p)

Expand All @@ -257,11 +307,19 @@ Dictionary objects
Return the number of items in the dictionary. This is equivalent to
``len(p)`` on a dictionary.

The argument can be a :class:`dict` or a :class:`frozendict`.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: Py_ssize_t PyDict_GET_SIZE(PyObject *p)

Similar to :c:func:`PyDict_Size`, but without error checking.

.. versionchanged:: next
Accept also :class:`frozendict`.


.. c:function:: int PyDict_Next(PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)

Expand All @@ -276,6 +334,8 @@ Dictionary objects
value represents offsets within the internal dictionary structure, and
since the structure is sparse, the offsets are not consecutive.

The first argument can be a :class:`dict` or a :class:`frozendict`.

For example::

PyObject *key, *value;
Expand Down Expand Up @@ -329,6 +389,9 @@ Dictionary objects
:term:`strong reference <strong reference>` (for example, using
:c:func:`Py_NewRef`).

.. versionchanged:: next
Accept also :class:`frozendict`.

.. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)

Iterate over mapping object *b* adding key-value pairs to dictionary *a*.
Expand Down
Loading