@@ -28,9 +28,9 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
28
28
29
29
.. c :function :: PyObject* PyMapping_GetItemString (PyObject *o, const char *key)
30
30
31
- Return element of * o * corresponding to the string *key * or `` NULL `` on failure.
32
- This is the equivalent of the Python expression `` o[key] ``.
33
- See also :c:func: ` PyObject_GetItem `.
31
+ This is the same as :c:func: ` PyObject_GetItem `, but *key * is
32
+ specified as a :c:expr: ` const char* ` UTF-8 encoded bytes string,
33
+ rather than a :c:expr: ` PyObject* `.
34
34
35
35
36
36
.. c :function :: int PyMapping_GetOptionalItem (PyObject *obj, PyObject *key, PyObject **result)
@@ -50,38 +50,30 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
50
50
51
51
.. c :function :: int PyMapping_GetOptionalItemString (PyObject *obj, const char *key, PyObject **result)
52
52
53
- Variant of :c:func: `PyMapping_GetItemString ` which doesn't raise
54
- :exc: `KeyError ` if the key is not found.
55
-
56
- If the key is found, return ``1 `` and set *\* result * to a new
57
- :term: `strong reference ` to the corresponding value.
58
- If the key is not found, return ``0 `` and set *\* result * to ``NULL ``;
59
- the :exc: `KeyError ` is silenced.
60
- If an error other than :exc: `KeyError ` is raised, return ``-1 `` and
61
- set *\* result * to ``NULL ``.
53
+ This is the same as :c:func: `PyMapping_GetOptionalItem `, but *key * is
54
+ specified as a :c:expr: `const char* ` UTF-8 encoded bytes string,
55
+ rather than a :c:expr: `PyObject* `.
62
56
63
57
.. versionadded :: 3.13
64
58
65
59
66
60
.. c :function :: int PyMapping_SetItemString (PyObject *o, const char *key, PyObject *v)
67
61
68
- Map the string *key * to the value *v * in object *o *. Returns ``-1 `` on
69
- failure. This is the equivalent of the Python statement ``o[key] = v ``.
70
- See also :c:func: `PyObject_SetItem `. This function *does not * steal a
71
- reference to *v *.
62
+ This is the same as :c:func: `PyObject_SetItem `, but *key * is
63
+ specified as a :c:expr: `const char* ` UTF-8 encoded bytes string,
64
+ rather than a :c:expr: `PyObject* `.
72
65
73
66
74
67
.. c :function :: int PyMapping_DelItem (PyObject *o, PyObject *key)
75
68
76
- Remove the mapping for the object *key * from the object *o *. Return ``-1 ``
77
- on failure. This is equivalent to the Python statement ``del o[key] ``.
78
69
This is an alias of :c:func: `PyObject_DelItem `.
79
70
80
71
81
72
.. c :function :: int PyMapping_DelItemString (PyObject *o, const char *key)
82
73
83
- Remove the mapping for the string *key * from the object *o *. Return ``-1 ``
84
- on failure. This is equivalent to the Python statement ``del o[key] ``.
74
+ This is the same as :c:func: `PyObject_DelItem `, but *key * is
75
+ specified as a :c:expr: `const char* ` UTF-8 encoded bytes string,
76
+ rather than a :c:expr: `PyObject* `.
85
77
86
78
87
79
.. c :function :: int PyMapping_HasKey (PyObject *o, PyObject *key)
@@ -90,20 +82,27 @@ See also :c:func:`PyObject_GetItem`, :c:func:`PyObject_SetItem` and
90
82
This is equivalent to the Python expression ``key in o ``.
91
83
This function always succeeds.
92
84
93
- Note that exceptions which occur while calling the :meth: `~object.__getitem__ `
94
- method will get suppressed.
95
- To get error reporting use :c:func: `PyObject_GetItem() ` instead.
85
+ .. note ::
86
+
87
+ Exceptions which occur when this calls :meth: `~object.__getitem__ `
88
+ method are silently ignored.
89
+ For proper error handling, use :c:func: `PyMapping_GetOptionalItem ` or
90
+ :c:func: `PyObject_GetItem() ` instead.
96
91
97
92
98
93
.. c :function :: int PyMapping_HasKeyString (PyObject *o, const char *key)
99
94
100
- Return ``1 `` if the mapping object has the key *key * and ``0 `` otherwise.
101
- This is equivalent to the Python expression ``key in o ``.
102
- This function always succeeds.
95
+ This is the same as :c:func: `PyMapping_HasKey `, but *key * is
96
+ specified as a :c:expr: `const char* ` UTF-8 encoded bytes string,
97
+ rather than a :c:expr: `PyObject* `.
98
+
99
+ .. note ::
103
100
104
- Note that exceptions which occur while calling the :meth: `~object.__getitem__ `
105
- method and creating a temporary string object will get suppressed.
106
- To get error reporting use :c:func: `PyMapping_GetItemString() ` instead.
101
+ Exceptions that occur when this calls :meth: `~object.__getitem__ `
102
+ method or while creating the temporary :class: `str `
103
+ object are silently ignored.
104
+ For proper error handling, use :c:func: `PyMapping_GetOptionalItemString ` or
105
+ :c:func: `PyMapping_GetItemString ` instead.
107
106
108
107
109
108
.. c :function :: PyObject* PyMapping_Keys (PyObject *o)
0 commit comments