]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-141004: Document `PyODict*` APIs (GH-141136) (GH-141678)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 17 Nov 2025 19:47:04 +0000 (20:47 +0100)
committerGitHub <noreply@github.com>
Mon, 17 Nov 2025 19:47:04 +0000 (19:47 +0000)
gh-141004: Document `PyODict*` APIs (GH-141136)
(cherry picked from commit b3626321b6ebb46dd24acee2aa806450e70febfc)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Doc/c-api/dict.rst
Doc/c-api/iterator.rst

index 676939308f24304724684b70fffa35a5ec6729e2..5f0faa6bc813d07ca07789db6239cac7ad7e39b0 100644 (file)
@@ -468,3 +468,92 @@ Dictionary View Objects
 
    Return true if *op* is an instance of a dictionary items view. This function
    always succeeds.
+
+
+Ordered Dictionaries
+^^^^^^^^^^^^^^^^^^^^
+
+Python's C API provides interface for :class:`collections.OrderedDict` from C.
+Since Python 3.7, dictionaries are ordered by default, so there is usually
+little need for these functions; prefer ``PyDict*`` where possible.
+
+
+.. c:var:: PyTypeObject PyODict_Type
+
+   Type object for ordered dictionaries. This is the same object as
+   :class:`collections.OrderedDict` in the Python layer.
+
+
+.. c:function:: int PyODict_Check(PyObject *od)
+
+   Return true if *od* is an ordered dictionary object or an instance of a
+   subtype of the :class:`~collections.OrderedDict` type.  This function
+   always succeeds.
+
+
+.. c:function:: int PyODict_CheckExact(PyObject *od)
+
+   Return true if *od* is an ordered dictionary object, but not an instance of
+   a subtype of the :class:`~collections.OrderedDict` type.
+   This function always succeeds.
+
+
+.. c:var:: PyTypeObject PyODictKeys_Type
+
+   Analogous to :c:type:`PyDictKeys_Type` for ordered dictionaries.
+
+
+.. c:var:: PyTypeObject PyODictValues_Type
+
+   Analogous to :c:type:`PyDictValues_Type` for ordered dictionaries.
+
+
+.. c:var:: PyTypeObject PyODictItems_Type
+
+   Analogous to :c:type:`PyDictItems_Type` for ordered dictionaries.
+
+
+.. c:function:: PyObject *PyODict_New(void)
+
+   Return a new empty ordered dictionary, or ``NULL`` on failure.
+
+   This is analogous to :c:func:`PyDict_New`.
+
+
+.. c:function:: int PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value)
+
+   Insert *value* into the ordered dictionary *od* with a key of *key*.
+   Return ``0`` on success or ``-1`` with an exception set on failure.
+
+   This is analogous to :c:func:`PyDict_SetItem`.
+
+
+.. c:function:: int PyODict_DelItem(PyObject *od, PyObject *key)
+
+   Remove the entry in the ordered dictionary *od* with key *key*.
+   Return ``0`` on success or ``-1`` with an exception set on failure.
+
+   This is analogous to :c:func:`PyDict_DelItem`.
+
+
+These are :term:`soft deprecated` aliases to ``PyDict`` APIs:
+
+
+.. list-table::
+   :widths: auto
+   :header-rows: 1
+
+   * * ``PyODict``
+     * ``PyDict``
+   * * .. c:macro:: PyODict_GetItem(od, key)
+     * :c:func:`PyDict_GetItem`
+   * * .. c:macro:: PyODict_GetItemWithError(od, key)
+     * :c:func:`PyDict_GetItemWithError`
+   * * .. c:macro:: PyODict_GetItemString(od, key)
+     * :c:func:`PyDict_GetItemString`
+   * * .. c:macro:: PyODict_Contains(od, key)
+     * :c:func:`PyDict_Contains`
+   * * .. c:macro:: PyODict_Size(od)
+     * :c:func:`PyDict_Size`
+   * * .. c:macro:: PyODict_SIZE(od)
+     * :c:func:`PyDict_GET_SIZE`
index 7eaf72ec55fd7715baf51b371cd8b0ecec37d3ba..bfbfe3c92799809a87d3d789c4935b3e499bb485 100644 (file)
@@ -108,6 +108,7 @@ Other Iterator Objects
 .. c:var:: PyTypeObject PyDictRevIterValue_Type
 .. c:var:: PyTypeObject PyDictIterItem_Type
 .. c:var:: PyTypeObject PyDictRevIterItem_Type
+.. c:var:: PyTypeObject PyODictIter_Type
 
    Type objects for iterators of various built-in objects.