Skip to content

Commit f3950f2

Browse files
committed
Document PyODict
1 parent 1697cb5 commit f3950f2

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

Doc/c-api/dict.rst

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,3 +431,91 @@ Dictionary Objects
431431
it before returning.
432432
433433
.. versionadded:: 3.12
434+
435+
436+
Ordered Dictionaries
437+
^^^^^^^^^^^^^^^^^^^^
438+
439+
Python's C API provides interface for :class:`collections.OrderedDict` from C.
440+
These APIs are mostly redundant; prefer ``PyDict*`` where possible.
441+
442+
443+
.. c:var:: PyTypeObject PyODict_Type
444+
445+
Type object for ordered dictionaries. This is the same object as
446+
:class:`collections.OrderedDict` in the Python layer.
447+
448+
Since Python 3.7, dictionaries are ordered by default, so there is usually
449+
little need for this object.
450+
451+
452+
.. c:function:: int PyODict_Check(PyObject *od)
453+
454+
Return true if *od* is an ordered dictionary object or an instance of a
455+
subtype of the :class:`~collections.OrderedDict` type. This function
456+
always succeeds.
457+
458+
459+
.. c:function:: int PyODict_CheckExact(PyObject *od)
460+
461+
Return true if *od* is a dict object, but not an instance of a subtype of
462+
the :class:`~collections.OrderedDict` type. This function always succeeds.
463+
464+
465+
.. c:var:: PyTypeObject PyODictKeys_Type
466+
467+
Analogous to :c:type:`!PyDictKeys_Type` for ordered dictionaries.
468+
469+
470+
.. c:var:: PyTypeObject PyODictValues_Type
471+
472+
Analogous to :c:type:`!PyDictValues_Type` for ordered dictionaries.
473+
474+
475+
.. c:var:: PyTypeObject PyODictItems_Type
476+
477+
Analogous to :c:type:`!PyDictItems_Type` for ordered dictionaries.
478+
479+
480+
.. c:function:: PyObject *PyODict_New(void)
481+
482+
Return a new empty ordered dictionary, or ``NULL`` on failure.
483+
484+
This is analogous to :c:func:`PyDict_New`.
485+
486+
487+
.. c:function:: int PyODict_SetItem(PyObject *od, PyObject *key, PyObject *value)
488+
489+
Insert *value* into the ordered dictionary *od* with a key of *key*.
490+
Return ``0`` on success or ``-1`` with an exception set on failure.
491+
492+
This is analogous to :c:func:`PyDict_SetItem`.
493+
494+
495+
.. c:function:: int PyODict_DelItem(PyObject *od, PyObject *key)
496+
497+
Remove the entry in the ordered dictionary *od* with key *key*.
498+
Return ``0`` on success or ``-1`` with an exception set on failure.
499+
500+
This is analogous to :c:func:`PyDict_DelItem`.
501+
502+
503+
These are :term:`soft deprecated` aliases to ``PyDict`` APIs:
504+
505+
506+
.. list-table::
507+
:widths: auto
508+
:header-rows: 1
509+
510+
* * ``PyODict``
511+
* ``PyDict``
512+
* * .. c:macro:: PyODict_GetItem(od, key)
513+
* :c:func:`PyDict_GetItem`
514+
* * .. c:macro:: PyODict_GetItemWithError(od, key)
515+
* :c:func:`PyDict_GetItemWithError`
516+
* * .. c:macro:: PyODict_GetItemString(od, key)
517+
* :c:func:`PyDict_GetItemString`
518+
* * .. c:macro:: PyODict_Contains(od, key)
519+
* :c:func:`PyDict_Contains`
520+
* * .. c:macro:: PyODict_SIZE(od)
521+
* :c:func:`PyDict_GET_SIZE`

0 commit comments

Comments
 (0)