Skip to content

Commit b94e32e

Browse files
ZeroIntensitymiss-islington
authored andcommitted
pythongh-141004: Document PyODict* APIs (pythonGH-141136)
(cherry picked from commit b362632) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent a63ceb7 commit b94e32e

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

Doc/c-api/dict.rst

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,92 @@ Dictionary View Objects
468468
469469
Return true if *op* is an instance of a dictionary items view. This function
470470
always succeeds.
471+
472+
473+
Ordered Dictionaries
474+
^^^^^^^^^^^^^^^^^^^^
475+
476+
Python's C API provides interface for :class:`collections.OrderedDict` from C.
477+
Since Python 3.7, dictionaries are ordered by default, so there is usually
478+
little need for these functions; prefer ``PyDict*`` where possible.
479+
480+
481+
.. c:var:: PyTypeObject PyODict_Type
482+
483+
Type object for ordered dictionaries. This is the same object as
484+
:class:`collections.OrderedDict` in the Python layer.
485+
486+
487+
.. c:function:: int PyODict_Check(PyObject *od)
488+
489+
Return true if *od* is an ordered dictionary object or an instance of a
490+
subtype of the :class:`~collections.OrderedDict` type. This function
491+
always succeeds.
492+
493+
494+
.. c:function:: int PyODict_CheckExact(PyObject *od)
495+
496+
Return true if *od* is an ordered dictionary object, but not an instance of
497+
a subtype of the :class:`~collections.OrderedDict` type.
498+
This function always succeeds.
499+
500+
501+
.. c:var:: PyTypeObject PyODictKeys_Type
502+
503+
Analogous to :c:type:`PyDictKeys_Type` for ordered dictionaries.
504+
505+
506+
.. c:var:: PyTypeObject PyODictValues_Type
507+
508+
Analogous to :c:type:`PyDictValues_Type` for ordered dictionaries.
509+
510+
511+
.. c:var:: PyTypeObject PyODictItems_Type
512+
513+
Analogous to :c:type:`PyDictItems_Type` for ordered dictionaries.
514+
515+
516+
.. c:function:: PyObject *PyODict_New(void)
517+
518+
Return a new empty ordered dictionary, or ``NULL`` on failure.
519+
520+
This is analogous to :c:func:`PyDict_New`.
521+
522+
523+
.. c:function:: int PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value)
524+
525+
Insert *value* into the ordered dictionary *od* with a key of *key*.
526+
Return ``0`` on success or ``-1`` with an exception set on failure.
527+
528+
This is analogous to :c:func:`PyDict_SetItem`.
529+
530+
531+
.. c:function:: int PyODict_DelItem(PyObject *od, PyObject *key)
532+
533+
Remove the entry in the ordered dictionary *od* with key *key*.
534+
Return ``0`` on success or ``-1`` with an exception set on failure.
535+
536+
This is analogous to :c:func:`PyDict_DelItem`.
537+
538+
539+
These are :term:`soft deprecated` aliases to ``PyDict`` APIs:
540+
541+
542+
.. list-table::
543+
:widths: auto
544+
:header-rows: 1
545+
546+
* * ``PyODict``
547+
* ``PyDict``
548+
* * .. c:macro:: PyODict_GetItem(od, key)
549+
* :c:func:`PyDict_GetItem`
550+
* * .. c:macro:: PyODict_GetItemWithError(od, key)
551+
* :c:func:`PyDict_GetItemWithError`
552+
* * .. c:macro:: PyODict_GetItemString(od, key)
553+
* :c:func:`PyDict_GetItemString`
554+
* * .. c:macro:: PyODict_Contains(od, key)
555+
* :c:func:`PyDict_Contains`
556+
* * .. c:macro:: PyODict_Size(od)
557+
* :c:func:`PyDict_Size`
558+
* * .. c:macro:: PyODict_SIZE(od)
559+
* :c:func:`PyDict_GET_SIZE`

Doc/c-api/iterator.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Other Iterator Objects
108108
.. c:var:: PyTypeObject PyDictRevIterValue_Type
109109
.. c:var:: PyTypeObject PyDictIterItem_Type
110110
.. c:var:: PyTypeObject PyDictRevIterItem_Type
111+
.. c:var:: PyTypeObject PyODictIter_Type
111112
112113
Type objects for iterators of various built-in objects.
113114

0 commit comments

Comments
 (0)