@@ -1416,8 +1416,8 @@ Key Exists
1416
1416
If the key already exists in the dictionary `PyDict_Pop() `_ returns 1.
1417
1417
The reference counts are changed as follows:
1418
1418
1419
- - key: unchanged.
1420
- - value: incremented by one
1419
+ - key: decremented by one
1420
+ - value: unchanged.
1421
1421
1422
1422
``*result `` is equal to the stored value.
1423
1423
@@ -1446,6 +1446,8 @@ For example:
1446
1446
* result: 2 as it equals val.
1447
1447
*/
1448
1448
1449
+ .. code-block :: c
1450
+
1449
1451
For code and tests see:
1450
1452
1451
1453
* C, in ``src/cpy/Containers/DebugContainers.c ``:
@@ -1508,6 +1510,11 @@ For code and tests see:
1508
1510
Failure
1509
1511
^^^^^^^
1510
1512
1513
+ .. todo ::
1514
+
1515
+ Finish Dictionary ``PyDict_Pop() `` Failure
1516
+
1517
+
1511
1518
.. index ::
1512
1519
single: Dictionary; Other APIs
1513
1520
@@ -1520,9 +1527,16 @@ This section describes other dictionary APIs that are simple to describe and hav
1520
1527
1521
1528
There are no tests for many of these APIs in the current version of this project.
1522
1529
1530
+ .. todo ::
1531
+
1532
+ Finish Dictionary "Other APIs"
1533
+
1523
1534
1524
1535
.. index ::
1525
1536
single: Dictionary; PyDict_GetItemWithError()
1537
+ pair: Documentation Lacunae; PyDict_GetItemWithError()
1538
+
1539
+ .. _chapter_containers_and_refcounts.dictionaries.pydict_getitemwitherror :
1526
1540
1527
1541
``PyDict_GetItemWithError() ``
1528
1542
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1536,6 +1550,34 @@ The C signature is:
1536
1550
1537
1551
PyObject *PyDict_GetItemWithError(PyObject *p, PyObject *key);
1538
1552
1553
+ .. warning ::
1554
+
1555
+ This function is incorrectly documented as it fails to set an exception with a missing key as this code
1556
+ demonstrates:
1557
+
1558
+ .. code-block :: c
1559
+
1560
+ assert(!PyErr_Occurred());
1561
+ PyObject *container = PyDict_New();
1562
+ assert(container && Py_REFCNT(container) == 1);
1563
+
1564
+ PyObject *key = new_unique_string(__FUNCTION__, NULL);
1565
+
1566
+ assert(!PyErr_Occurred());
1567
+ PyObject *get_item = PyDict_GetItemWithError(container, key);
1568
+ /* This is the failure point. An exception should have been set with
1569
+ * an absent key but it isn't. */
1570
+ assert(!PyErr_Occurred());
1571
+
1572
+ assert(get_item == NULL);
1573
+
1574
+ Py_DECREF(container);
1575
+ Py_DECREF(key);
1576
+
1577
+ For code and tests see:
1578
+
1579
+ * C, in ``src/cpy/Containers/DebugContainers.c ``:
1580
+ * ``dbg_PyDict_GetItemWithError_fails() ``
1539
1581
1540
1582
.. index ::
1541
1583
single: Dictionary; PyDict_DelItem()
@@ -1554,6 +1596,9 @@ The C function signature is:
1554
1596
1555
1597
int PyDict_DelItem(PyObject *p, PyObject *key);
1556
1598
1599
+ .. todo ::
1600
+
1601
+ Complete ``PyDict_DelItem() `` with code examples.
1557
1602
1558
1603
.. index ::
1559
1604
single: Dictionary; PyDict_Items()
@@ -1572,6 +1617,9 @@ The C function signature is:
1572
1617
1573
1618
Pyobject *PyDict_Items(PyObject *p);
1574
1619
1620
+ .. todo ::
1621
+
1622
+ Complete ``PyDict_Items() `` with code examples.
1575
1623
1576
1624
.. index ::
1577
1625
single: Dictionary; PyDict_Keys()
@@ -1590,6 +1638,9 @@ The C function signature is:
1590
1638
1591
1639
Pyobject *PyDict_Keys(PyObject *p);
1592
1640
1641
+ .. todo ::
1642
+
1643
+ Complete ``PyDict_Keys() `` with code examples.
1593
1644
1594
1645
.. index ::
1595
1646
single: Dictionary; PyDict_Values()
@@ -1608,6 +1659,9 @@ The C function signature is:
1608
1659
1609
1660
Pyobject *PyDict_Values(PyObject *p);
1610
1661
1662
+ .. todo ::
1663
+
1664
+ Complete ``PyDict_Values() `` with code examples.
1611
1665
1612
1666
.. index ::
1613
1667
single: Dictionary; PyDict_Next()
@@ -1623,6 +1677,10 @@ The C function signature is:
1623
1677
1624
1678
int PyDict_Next(PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue);
1625
1679
1680
+ .. todo ::
1681
+
1682
+ Complete ``PyDict_Next() `` with code examples.
1683
+
1626
1684
.. index ::
1627
1685
single: Dictionary; Py_BuildValue()
1628
1686
@@ -1633,7 +1691,6 @@ The C function signature is:
1633
1691
``Py_BuildValue("{OO}", key, value); `` will increment the refcount of the key and value and this can,
1634
1692
potentially, leak.
1635
1693
1636
-
1637
1694
.. Links, mostly to the Python documentation:
1638
1695
1639
1696
.. Setters
@@ -1898,6 +1955,12 @@ Dictionaries
1898
1955
See :ref: `chapter_containers_and_refcounts.dictionaries.setitem.failure `.
1899
1956
- `PyDict_SetDefault() `_ has generally graceful behaviour on failure.
1900
1957
See :ref: `chapter_containers_and_refcounts.dictionaries.setdefault `.
1958
+ - `PyDict_GetItemWithError() `_ is incorrectly implemented or documented.
1959
+ See :ref: `chapter_containers_and_refcounts.dictionaries.pydict_getitemwitherror `.
1960
+
1961
+ .. todo ::
1962
+
1963
+ Complete the summary of dictionary APIs and their documentation lacunae.
1901
1964
1902
1965
Sets
1903
1966
--------------
0 commit comments