Changeset 391 for python/trunk/Doc/c-api/object.rst
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/c-api/object.rst
r2 r391 7 7 8 8 9 .. c function:: int PyObject_Print(PyObject *o, FILE *fp, int flags)9 .. c:function:: int PyObject_Print(PyObject *o, FILE *fp, int flags) 10 10 11 11 Print an object *o*, on file *fp*. Returns ``-1`` on error. The flags argument … … 15 15 16 16 17 .. c function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name)17 .. c:function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name) 18 18 19 19 Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This … … 22 22 23 23 24 .. c function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name)24 .. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name) 25 25 26 26 Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This … … 29 29 30 30 31 .. c function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name)31 .. c:function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name) 32 32 33 33 Retrieve an attribute named *attr_name* from object *o*. Returns the attribute … … 36 36 37 37 38 .. c function:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name)38 .. c:function:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name) 39 39 40 40 Retrieve an attribute named *attr_name* from object *o*. Returns the attribute … … 43 43 44 44 45 .. c function:: PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name)45 .. c:function:: PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name) 46 46 47 47 Generic attribute getter function that is meant to be put into a type 48 48 object's ``tp_getattro`` slot. It looks for a descriptor in the dictionary 49 49 of classes in the object's MRO as well as an attribute in the object's 50 :attr:` __dict__` (if present). As outlined in :ref:`descriptors`, data51 d escriptors take preference over instance attributes, while non-data50 :attr:`~object.__dict__` (if present). As outlined in :ref:`descriptors`, 51 data descriptors take preference over instance attributes, while non-data 52 52 descriptors don't. Otherwise, an :exc:`AttributeError` is raised. 53 53 54 54 55 .. c function:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v)55 .. c:function:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) 56 56 57 57 Set the value of the attribute named *attr_name*, for object *o*, to the value … … 60 60 61 61 62 .. c function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)62 .. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) 63 63 64 64 Set the value of the attribute named *attr_name*, for object *o*, to the value … … 67 67 68 68 69 .. c function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)69 .. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value) 70 70 71 71 Generic attribute setter function that is meant to be put into a type … … 73 73 dictionary of classes in the object's MRO, and if found it takes preference 74 74 over setting the attribute in the instance dictionary. Otherwise, the 75 attribute is set in the object's :attr:` __dict__` (if present). Otherwise,76 an :exc:`AttributeError` is raised and ``-1`` is returned.77 78 79 .. c function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name)75 attribute is set in the object's :attr:`~object.__dict__` (if present). 76 Otherwise, an :exc:`AttributeError` is raised and ``-1`` is returned. 77 78 79 .. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) 80 80 81 81 Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. … … 83 83 84 84 85 .. c function:: int PyObject_DelAttrString(PyObject *o, const char *attr_name)85 .. c:function:: int PyObject_DelAttrString(PyObject *o, const char *attr_name) 86 86 87 87 Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. … … 89 89 90 90 91 .. c function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)91 .. c:function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid) 92 92 93 93 Compare the values of *o1* and *o2* using the operation specified by *opid*, … … 99 99 100 100 101 .. c function:: int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid)101 .. c:function:: int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid) 102 102 103 103 Compare the values of *o1* and *o2* using the operation specified by *opid*, … … 109 109 *opid*. 110 110 111 112 .. cfunction:: int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result) 111 .. note:: 112 If *o1* and *o2* are the same object, :c:func:`PyObject_RichCompareBool` 113 will always return ``1`` for :const:`Py_EQ` and ``0`` for :const:`Py_NE`. 114 115 .. c:function:: int PyObject_Cmp(PyObject *o1, PyObject *o2, int *result) 113 116 114 117 .. index:: builtin: cmp … … 120 123 121 124 122 .. c function:: int PyObject_Compare(PyObject *o1, PyObject *o2)125 .. c:function:: int PyObject_Compare(PyObject *o1, PyObject *o2) 123 126 124 127 .. index:: builtin: cmp … … 127 130 exists, otherwise with a routine provided by *o2*. Returns the result of the 128 131 comparison on success. On error, the value returned is undefined; use 129 :c func:`PyErr_Occurred` to detect an error. This is equivalent to the Python132 :c:func:`PyErr_Occurred` to detect an error. This is equivalent to the Python 130 133 expression ``cmp(o1, o2)``. 131 134 132 135 133 .. c function:: PyObject* PyObject_Repr(PyObject *o)136 .. c:function:: PyObject* PyObject_Repr(PyObject *o) 134 137 135 138 .. index:: builtin: repr … … 141 144 142 145 143 .. c function:: PyObject* PyObject_Str(PyObject *o)146 .. c:function:: PyObject* PyObject_Str(PyObject *o) 144 147 145 148 .. index:: builtin: str … … 151 154 152 155 153 .. c function:: PyObject* PyObject_Bytes(PyObject *o)156 .. c:function:: PyObject* PyObject_Bytes(PyObject *o) 154 157 155 158 .. index:: builtin: bytes 156 159 157 160 Compute a bytes representation of object *o*. In 2.x, this is just a alias 158 for :c func:`PyObject_Str`.159 160 161 .. c function:: PyObject* PyObject_Unicode(PyObject *o)161 for :c:func:`PyObject_Str`. 162 163 164 .. c:function:: PyObject* PyObject_Unicode(PyObject *o) 162 165 163 166 .. index:: builtin: unicode … … 169 172 170 173 171 .. c function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)174 .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) 172 175 173 176 Returns ``1`` if *inst* is an instance of the class *cls* or a subclass of 174 177 *cls*, or ``0`` if not. On error, returns ``-1`` and sets an exception. If 175 *cls* is a type object rather than a class object, :c func:`PyObject_IsInstance`178 *cls* is a type object rather than a class object, :c:func:`PyObject_IsInstance` 176 179 returns ``1`` if *inst* is of type *cls*. If *cls* is a tuple, the check will 177 180 be done against every entry in *cls*. The result will be ``1`` when at least one 178 181 of the checks returns ``1``, otherwise it will be ``0``. If *inst* is not a 179 182 class instance and *cls* is neither a type object, nor a class object, nor a 180 tuple, *inst* must have a :attr:` __class__` attribute --- the class relationship181 of the value of that attribute with *cls* will be used to determine the result182 of this function.183 tuple, *inst* must have a :attr:`~instance.__class__` attribute --- the 184 class relationship of the value of that attribute with *cls* will be used 185 to determine the result of this function. 183 186 184 187 .. versionadded:: 2.1 … … 193 196 either is not a class object, a more general mechanism is used to determine the 194 197 class relationship of the two objects. When testing if *B* is a subclass of 195 *A*, if *A* is *B*, :c func:`PyObject_IsSubclass` returns true. If *A* and *B*196 are different objects, *B*'s :attr:` __bases__` attribute is searched in a197 depth-first fashion for *A* --- the presence of the :attr:`__bases__` attribute 198 is considered sufficient for this determination.199 200 201 .. c function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls)198 *A*, if *A* is *B*, :c:func:`PyObject_IsSubclass` returns true. If *A* and *B* 199 are different objects, *B*'s :attr:`~class.__bases__` attribute is searched in 200 a depth-first fashion for *A* --- the presence of the :attr:`~class.__bases__` 201 attribute is considered sufficient for this determination. 202 203 204 .. c:function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls) 202 205 203 206 Returns ``1`` if the class *derived* is identical to or derived from the class … … 214 217 215 218 216 .. c function:: int PyCallable_Check(PyObject *o)219 .. c:function:: int PyCallable_Check(PyObject *o) 217 220 218 221 Determine if the object *o* is callable. Return ``1`` if the object is callable … … 220 223 221 224 222 .. c function:: PyObject* PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw)225 .. c:function:: PyObject* PyObject_Call(PyObject *callable_object, PyObject *args, PyObject *kw) 223 226 224 227 .. index:: builtin: apply … … 234 237 235 238 236 .. c function:: PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args)239 .. c:function:: PyObject* PyObject_CallObject(PyObject *callable_object, PyObject *args) 237 240 238 241 .. index:: builtin: apply … … 245 248 246 249 247 .. c function:: PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...)250 .. c:function:: PyObject* PyObject_CallFunction(PyObject *callable, char *format, ...) 248 251 249 252 .. index:: builtin: apply 250 253 251 254 Call a callable Python object *callable*, with a variable number of C arguments. 252 The C arguments are described using a :c func:`Py_BuildValue` style format255 The C arguments are described using a :c:func:`Py_BuildValue` style format 253 256 string. The format may be *NULL*, indicating that no arguments are provided. 254 257 Returns the result of the call on success, or *NULL* on failure. This is the 255 258 equivalent of the Python expression ``apply(callable, args)`` or 256 ``callable(*args)``. Note that if you only pass :c type:`PyObject \*` args,257 :c func:`PyObject_CallFunctionObjArgs` is a faster alternative.258 259 260 .. c function:: PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...)259 ``callable(*args)``. Note that if you only pass :c:type:`PyObject \*` args, 260 :c:func:`PyObject_CallFunctionObjArgs` is a faster alternative. 261 262 263 .. c:function:: PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...) 261 264 262 265 Call the method named *method* of object *o* with a variable number of C 263 arguments. The C arguments are described by a :c func:`Py_BuildValue` format266 arguments. The C arguments are described by a :c:func:`Py_BuildValue` format 264 267 string that should produce a tuple. The format may be *NULL*, indicating that 265 268 no arguments are provided. Returns the result of the call on success, or *NULL* 266 269 on failure. This is the equivalent of the Python expression ``o.method(args)``. 267 Note that if you only pass :c type:`PyObject \*` args,268 :c func:`PyObject_CallMethodObjArgs` is a faster alternative.269 270 271 .. c function:: PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL)270 Note that if you only pass :c:type:`PyObject \*` args, 271 :c:func:`PyObject_CallMethodObjArgs` is a faster alternative. 272 273 274 .. c:function:: PyObject* PyObject_CallFunctionObjArgs(PyObject *callable, ..., NULL) 272 275 273 276 Call a callable Python object *callable*, with a variable number of 274 :c type:`PyObject\*` arguments. The arguments are provided as a variable number277 :c:type:`PyObject\*` arguments. The arguments are provided as a variable number 275 278 of parameters followed by *NULL*. Returns the result of the call on success, or 276 279 *NULL* on failure. … … 279 282 280 283 281 .. c function:: PyObject* PyObject_CallMethodObjArgs(PyObject *o, PyObject *name, ..., NULL)284 .. c:function:: PyObject* PyObject_CallMethodObjArgs(PyObject *o, PyObject *name, ..., NULL) 282 285 283 286 Calls a method of the object *o*, where the name of the method is given as a 284 287 Python string object in *name*. It is called with a variable number of 285 :c type:`PyObject\*` arguments. The arguments are provided as a variable number288 :c:type:`PyObject\*` arguments. The arguments are provided as a variable number 286 289 of parameters followed by *NULL*. Returns the result of the call on success, or 287 290 *NULL* on failure. … … 290 293 291 294 292 .. c function:: long PyObject_Hash(PyObject *o)295 .. c:function:: long PyObject_Hash(PyObject *o) 293 296 294 297 .. index:: builtin: hash … … 298 301 299 302 300 .. c function:: long PyObject_HashNotImplemented(PyObject *o)303 .. c:function:: long PyObject_HashNotImplemented(PyObject *o) 301 304 302 305 Set a :exc:`TypeError` indicating that ``type(o)`` is not hashable and return ``-1``. … … 308 311 309 312 310 .. c function:: int PyObject_IsTrue(PyObject *o)313 .. c:function:: int PyObject_IsTrue(PyObject *o) 311 314 312 315 Returns ``1`` if the object *o* is considered to be true, and ``0`` otherwise. … … 315 318 316 319 317 .. c function:: int PyObject_Not(PyObject *o)320 .. c:function:: int PyObject_Not(PyObject *o) 318 321 319 322 Returns ``0`` if the object *o* is considered to be true, and ``1`` otherwise. … … 322 325 323 326 324 .. c function:: PyObject* PyObject_Type(PyObject *o)327 .. c:function:: PyObject* PyObject_Type(PyObject *o) 325 328 326 329 .. index:: builtin: type … … 331 334 reference count of the return value. There's really no reason to use this 332 335 function instead of the common expression ``o->ob_type``, which returns a 333 pointer of type :c type:`PyTypeObject\*`, except when the incremented reference336 pointer of type :c:type:`PyTypeObject\*`, except when the incremented reference 334 337 count is needed. 335 338 336 339 337 .. c function:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type)340 .. c:function:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type) 338 341 339 342 Return true if the object *o* is of type *type* or a subtype of *type*. Both … … 343 346 344 347 345 .. c function:: Py_ssize_t PyObject_Length(PyObject *o)348 .. c:function:: Py_ssize_t PyObject_Length(PyObject *o) 346 349 Py_ssize_t PyObject_Size(PyObject *o) 347 350 … … 353 356 354 357 .. versionchanged:: 2.5 355 These functions returned an :c type:`int` type. This might require358 These functions returned an :c:type:`int` type. This might require 356 359 changes in your code for properly supporting 64-bit systems. 357 360 358 361 359 .. c function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key)362 .. c:function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key) 360 363 361 364 Return element of *o* corresponding to the object *key* or *NULL* on failure. … … 363 366 364 367 365 .. c function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v)368 .. c:function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v) 366 369 367 370 Map the object *key* to the value *v*. Returns ``-1`` on failure. This is the … … 369 372 370 373 371 .. c function:: int PyObject_DelItem(PyObject *o, PyObject *key)374 .. c:function:: int PyObject_DelItem(PyObject *o, PyObject *key) 372 375 373 376 Delete the mapping for *key* from *o*. Returns ``-1`` on failure. This is the … … 375 378 376 379 377 .. c function:: int PyObject_AsFileDescriptor(PyObject *o)380 .. c:function:: int PyObject_AsFileDescriptor(PyObject *o) 378 381 379 382 Derives a file descriptor from a Python object. If the object is an integer or … … 383 386 384 387 385 .. c function:: PyObject* PyObject_Dir(PyObject *o)388 .. c:function:: PyObject* PyObject_Dir(PyObject *o) 386 389 387 390 This is equivalent to the Python expression ``dir(o)``, returning a (possibly … … 389 392 was an error. If the argument is *NULL*, this is like the Python ``dir()``, 390 393 returning the names of the current locals; in this case, if no execution frame 391 is active then *NULL* is returned but :c func:`PyErr_Occurred` will return false.392 393 394 .. c function:: PyObject* PyObject_GetIter(PyObject *o)394 is active then *NULL* is returned but :c:func:`PyErr_Occurred` will return false. 395 396 397 .. c:function:: PyObject* PyObject_GetIter(PyObject *o) 395 398 396 399 This is equivalent to the Python expression ``iter(o)``. It returns a new
Note:
See TracChangeset
for help on using the changeset viewer.