| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent f174689 commit 45be8d6
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,25 +68,35 @@ Object Protocol | |||
| 68 | 68 | .. c:function:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) | |
| 69 | 69 | ||
| 70 | 70 | Set the value of the attribute named *attr_name*, for object *o*, to the value | |
| 71 | - *v*. Returns ``-1`` on failure. This is the equivalent of the Python statement | ||
| 71 | + *v*. Raise an exception and return ``-1`` on failure; | ||
| 72 | + return ``0`` on success. This is the equivalent of the Python statement | ||
| 72 | 73 | ``o.attr_name = v``. | |
| 73 | 74 | ||
| 75 | + If *v* is *NULL*, the attribute is deleted, however this feature is | ||
| 76 | + deprecated in favour of using :c:func:`PyObject_DelAttr`. | ||
| 77 | + | ||
| 74 | 78 | ||
| 75 | 79 | .. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) | |
| 76 | 80 | ||
| 77 | 81 | Set the value of the attribute named *attr_name*, for object *o*, to the value | |
| 78 | - *v*. Returns ``-1`` on failure. This is the equivalent of the Python statement | ||
| 82 | + *v*. Raise an exception and return ``-1`` on failure; | ||
| 83 | + return ``0`` on success. This is the equivalent of the Python statement | ||
| 79 | 84 | ``o.attr_name = v``. | |
| 80 | 85 | ||
| 86 | + If *v* is *NULL*, the attribute is deleted, however this feature is | ||
| 87 | + deprecated in favour of using :c:func:`PyObject_DelAttrString`. | ||
| 88 | + | ||
| 81 | 89 | ||
| 82 | 90 | .. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value) | |
| 83 | 91 | ||
| 84 | - Generic attribute setter function that is meant to be put into a type | ||
| 85 | - object's ``tp_setattro`` slot. It looks for a data descriptor in the | ||
| 92 | + Generic attribute setter and deleter function that is meant | ||
| 93 | + to be put into a type object's :c:member:`~PyTypeObject.tp_setattro` | ||
| 94 | + slot. It looks for a data descriptor in the | ||
| 86 | 95 | dictionary of classes in the object's MRO, and if found it takes preference | |
| 87 | - over setting the attribute in the instance dictionary. Otherwise, the | ||
| 88 | - attribute is set in the object's :attr:`~object.__dict__` (if present). | ||
| 89 | - Otherwise, an :exc:`AttributeError` is raised and ``-1`` is returned. | ||
| 96 | + over setting or deleting the attribute in the instance dictionary. Otherwise, the | ||
| 97 | + attribute is set or deleted in the object's :attr:`~object.__dict__` (if present). | ||
| 98 | + On success, ``0`` is returned, otherwise an :exc:`AttributeError` | ||
| 99 | + is raised and ``-1`` is returned. | ||
| 90 | 100 | ||
| 91 | 101 | ||
| 92 | 102 | .. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) | |
@@ -378,7 +388,8 @@ Object Protocol | |||
| 378 | 388 | ||
| 379 | 389 | .. c:function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v) | |
| 380 | 390 | ||
| 381 | - Map the object *key* to the value *v*. Returns ``-1`` on failure. This is the | ||
| 391 | + Map the object *key* to the value *v*. Raise an exception and | ||
| 392 | + return ``-1`` on failure; return ``0`` on success. This is the | ||
| 382 | 393 | equivalent of the Python statement ``o[key] = v``. | |
| 383 | 394 | ||
| 384 | 395 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,10 +62,14 @@ Sequence Protocol | |||
| 62 | 62 | ||
| 63 | 63 | .. c:function:: int PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v) | |
| 64 | 64 | ||
| 65 | - Assign object *v* to the *i*\ th element of *o*. Returns ``-1`` on failure. This | ||
| 65 | + Assign object *v* to the *i*\ th element of *o*. Raise an exception | ||
| 66 | + and return ``-1`` on failure; return ``0`` on success. This | ||
| 66 | 67 | is the equivalent of the Python statement ``o[i] = v``. This function *does | |
| 67 | 68 | not* steal a reference to *v*. | |
| 68 | 69 | ||
| 70 | + If *v* is *NULL*, the element is deleted, however this feature is | ||
| 71 | + deprecated in favour of using :c:func:`PySequence_DelItem`. | ||
| 72 | + | ||
| 69 | 73 | ||
| 70 | 74 | .. c:function:: int PySequence_DelItem(PyObject *o, Py_ssize_t i) | |
| 71 | 75 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,12 +208,13 @@ type objects) *must* have the :attr:`ob_size` field. | |||
| 208 | 208 | ||
| 209 | 209 | .. c:member:: setattrfunc PyTypeObject.tp_setattr | |
| 210 | 210 | ||
| 211 | - An optional pointer to the set-attribute-string function. | ||
| 211 | + An optional pointer to the function for setting and deleting attributes. | ||
| 212 | 212 | ||
| 213 | 213 | This field is deprecated. When it is defined, it should point to a function | |
| 214 | 214 | that acts the same as the :c:member:`~PyTypeObject.tp_setattro` function, but taking a C string | |
| 215 | 215 | instead of a Python string object to give the attribute name. The signature is | |
| 216 | - the same as for :c:func:`PyObject_SetAttrString`. | ||
| 216 | + the same as for :c:func:`PyObject_SetAttrString`, but setting | ||
| 217 | + *v* to *NULL* to delete an attribute must be supported. | ||
| 217 | 218 | ||
| 218 | 219 | This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_setattro`: a subtype | |
| 219 | 220 | inherits both :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` from its base type when | |
@@ -351,9 +352,10 @@ type objects) *must* have the :attr:`ob_size` field. | |||
| 351 | 352 | ||
| 352 | 353 | .. c:member:: setattrofunc PyTypeObject.tp_setattro | |
| 353 | 354 | ||
| 354 | - An optional pointer to the set-attribute function. | ||
| 355 | + An optional pointer to the function for setting and deleting attributes. | ||
| 355 | 356 | ||
| 356 | - The signature is the same as for :c:func:`PyObject_SetAttr`. It is usually | ||
| 357 | + The signature is the same as for :c:func:`PyObject_SetAttr`, but setting | ||
| 358 | + *v* to *NULL* to delete an attribute must be supported. It is usually | ||
| 357 | 359 | convenient to set this field to :c:func:`PyObject_GenericSetAttr`, which | |
| 358 | 360 | implements the normal way of setting object attributes. | |
| 359 | 361 | ||
@@ -724,7 +726,7 @@ type objects) *must* have the :attr:`ob_size` field. | |||
| 724 | 726 | typedef struct PyGetSetDef { | |
| 725 | 727 | char *name; /* attribute name */ | |
| 726 | 728 | getter get; /* C function to get the attribute */ | |
| 727 | - setter set; /* C function to set the attribute */ | ||
| 729 | + setter set; /* C function to set or delete the attribute */ | ||
| 728 | 730 | char *doc; /* optional doc string */ | |
| 729 | 731 | void *closure; /* optional additional data for getter and setter */ | |
| 730 | 732 | } PyGetSetDef; | |
@@ -775,12 +777,14 @@ type objects) *must* have the :attr:`ob_size` field. | |||
| 775 | 777 | ||
| 776 | 778 | .. c:member:: descrsetfunc PyTypeObject.tp_descr_set | |
| 777 | 779 | ||
| 778 | - An optional pointer to a "descriptor set" function. | ||
| 780 | + An optional pointer to a function for setting and deleting | ||
| 781 | + a descriptor's value. | ||
| 779 | 782 | ||
| 780 | 783 | The function signature is :: | |
| 781 | 784 | ||
| 782 | 785 | int tp_descr_set(PyObject *self, PyObject *obj, PyObject *value); | |
| 783 | 786 | ||
| 787 | + The *value* argument is set to *NULL* to delete the value. | ||
| 784 | 788 | This field is inherited by subtypes. | |
| 785 | 789 | ||
| 786 | 790 | .. XXX explain. | |
@@ -1171,9 +1175,11 @@ Mapping Object Structures | |||
| 1171 | 1175 | ||
| 1172 | 1176 | .. c:member:: objobjargproc PyMappingMethods.mp_ass_subscript | |
| 1173 | 1177 | ||
| 1174 | - This function is used by :c:func:`PyObject_SetItem` and has the same | ||
| 1175 | - signature. If this slot is *NULL*, the object does not support item | ||
| 1176 | - assignment. | ||
| 1178 | + This function is used by :c:func:`PyObject_SetItem` and | ||
| 1179 | + :c:func:`PyObject_DelItem`. It has the same signature as | ||
| 1180 | + :c:func:`PyObject_SetItem`, but *v* can also be set to *NULL* to delete | ||
| 1181 | + an item. If this slot is *NULL*, the object does not support item | ||
| 1182 | + assignment and deletion. | ||
| 1177 | 1183 | ||
| 1178 | 1184 | ||
| 1179 | 1185 | .. _sequence-structs: | |
@@ -1222,7 +1228,7 @@ Sequence Object Structures | |||
| 1222 | 1228 | ||
| 1223 | 1229 | This function is used by :c:func:`PySequence_SetItem` and has the same | |
| 1224 | 1230 | signature. This slot may be left to *NULL* if the object does not support | |
| 1225 | - item assignment. | ||
| 1231 | + item assignment and deletion. | ||
| 1226 | 1232 | ||
| 1227 | 1233 | .. c:member:: objobjproc PySequenceMethods.sq_contains | |
| 1228 | 1234 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -192,8 +192,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ | |||
| 192 | 192 | int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v); | |
| 193 | 193 | ||
| 194 | 194 | Set the value of the attribute named attr_name, for object o, | |
| 195 | - to the value, v. Returns -1 on failure. This is | ||
| 196 | - the equivalent of the Python statement: o.attr_name=v. | ||
| 195 | + to the value v. Raise an exception and return -1 on failure; return 0 on | ||
| 196 | + success. This is the equivalent of the Python statement o.attr_name=v. | ||
| 197 | 197 | ||
| 198 | 198 | */ | |
| 199 | 199 | ||
@@ -202,8 +202,8 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ | |||
| 202 | 202 | int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v); | |
| 203 | 203 | ||
| 204 | 204 | Set the value of the attribute named attr_name, for object o, | |
| 205 | - to the value, v. Returns -1 on failure. This is | ||
| 206 | - the equivalent of the Python statement: o.attr_name=v. | ||
| 205 | + to the value v. Raise an exception and return -1 on failure; return 0 on | ||
| 206 | + success. This is the equivalent of the Python statement o.attr_name=v. | ||
| 207 | 207 | ||
| 208 | 208 | */ | |
| 209 | 209 | ||
@@ -435,9 +435,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ | |||
| 435 | 435 | PyAPI_FUNC(int) PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v); | |
| 436 | 436 | ||
| 437 | 437 | /* | |
| 438 | - Map the object, key, to the value, v. Returns | ||
| 439 | - -1 on failure. This is the equivalent of the Python | ||
| 440 | - statement: o[key]=v. | ||
| 438 | + Map the object key to the value v. Raise an exception and return -1 | ||
| 439 | + on failure; return 0 on success. This is the equivalent of the Python | ||
| 440 | + statement o[key]=v. | ||
| 441 | 441 | */ | |
| 442 | 442 | ||
| 443 | 443 | PyAPI_FUNC(int) PyObject_DelItemString(PyObject *o, const char *key); | |
@@ -993,9 +993,9 @@ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ | |||
| 993 | 993 | PyAPI_FUNC(int) PySequence_SetItem(PyObject *o, Py_ssize_t i, PyObject *v); | |
| 994 | 994 | ||
| 995 | 995 | /* | |
| 996 | - Assign object v to the ith element of o. Returns | ||
| 997 | - -1 on failure. This is the equivalent of the Python | ||
| 998 | - statement: o[i]=v. | ||
| 996 | + Assign object v to the ith element of o. Raise an exception and return | ||
| 997 | + -1 on failure; return 0 on success. This is the equivalent of the | ||
| 998 | + Python statement o[i]=v. | ||
| 999 | 999 | */ | |
| 1000 | 1000 | ||
| 1001 | 1001 | PyAPI_FUNC(int) PySequence_DelItem(PyObject *o, Py_ssize_t i); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments