17db96d56Sopenharmony_ci.. highlight:: c 27db96d56Sopenharmony_ci 37db96d56Sopenharmony_ci.. _object: 47db96d56Sopenharmony_ci 57db96d56Sopenharmony_ciObject Protocol 67db96d56Sopenharmony_ci=============== 77db96d56Sopenharmony_ci 87db96d56Sopenharmony_ci 97db96d56Sopenharmony_ci.. c:var:: PyObject* Py_NotImplemented 107db96d56Sopenharmony_ci 117db96d56Sopenharmony_ci The ``NotImplemented`` singleton, used to signal that an operation is 127db96d56Sopenharmony_ci not implemented for the given type combination. 137db96d56Sopenharmony_ci 147db96d56Sopenharmony_ci 157db96d56Sopenharmony_ci.. c:macro:: Py_RETURN_NOTIMPLEMENTED 167db96d56Sopenharmony_ci 177db96d56Sopenharmony_ci Properly handle returning :c:data:`Py_NotImplemented` from within a C 187db96d56Sopenharmony_ci function (that is, increment the reference count of NotImplemented and 197db96d56Sopenharmony_ci return it). 207db96d56Sopenharmony_ci 217db96d56Sopenharmony_ci 227db96d56Sopenharmony_ci.. c:function:: int PyObject_Print(PyObject *o, FILE *fp, int flags) 237db96d56Sopenharmony_ci 247db96d56Sopenharmony_ci Print an object *o*, on file *fp*. Returns ``-1`` on error. The flags argument 257db96d56Sopenharmony_ci is used to enable certain printing options. The only option currently supported 267db96d56Sopenharmony_ci is :const:`Py_PRINT_RAW`; if given, the :func:`str` of the object is written 277db96d56Sopenharmony_ci instead of the :func:`repr`. 287db96d56Sopenharmony_ci 297db96d56Sopenharmony_ci 307db96d56Sopenharmony_ci.. c:function:: int PyObject_HasAttr(PyObject *o, PyObject *attr_name) 317db96d56Sopenharmony_ci 327db96d56Sopenharmony_ci Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This 337db96d56Sopenharmony_ci is equivalent to the Python expression ``hasattr(o, attr_name)``. This function 347db96d56Sopenharmony_ci always succeeds. 357db96d56Sopenharmony_ci 367db96d56Sopenharmony_ci Note that exceptions which occur while calling :meth:`__getattr__` and 377db96d56Sopenharmony_ci :meth:`__getattribute__` methods will get suppressed. 387db96d56Sopenharmony_ci To get error reporting use :c:func:`PyObject_GetAttr()` instead. 397db96d56Sopenharmony_ci 407db96d56Sopenharmony_ci 417db96d56Sopenharmony_ci.. c:function:: int PyObject_HasAttrString(PyObject *o, const char *attr_name) 427db96d56Sopenharmony_ci 437db96d56Sopenharmony_ci Returns ``1`` if *o* has the attribute *attr_name*, and ``0`` otherwise. This 447db96d56Sopenharmony_ci is equivalent to the Python expression ``hasattr(o, attr_name)``. This function 457db96d56Sopenharmony_ci always succeeds. 467db96d56Sopenharmony_ci 477db96d56Sopenharmony_ci Note that exceptions which occur while calling :meth:`__getattr__` and 487db96d56Sopenharmony_ci :meth:`__getattribute__` methods and creating a temporary string object 497db96d56Sopenharmony_ci will get suppressed. 507db96d56Sopenharmony_ci To get error reporting use :c:func:`PyObject_GetAttrString()` instead. 517db96d56Sopenharmony_ci 527db96d56Sopenharmony_ci 537db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_GetAttr(PyObject *o, PyObject *attr_name) 547db96d56Sopenharmony_ci 557db96d56Sopenharmony_ci Retrieve an attribute named *attr_name* from object *o*. Returns the attribute 567db96d56Sopenharmony_ci value on success, or ``NULL`` on failure. This is the equivalent of the Python 577db96d56Sopenharmony_ci expression ``o.attr_name``. 587db96d56Sopenharmony_ci 597db96d56Sopenharmony_ci 607db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_GetAttrString(PyObject *o, const char *attr_name) 617db96d56Sopenharmony_ci 627db96d56Sopenharmony_ci Retrieve an attribute named *attr_name* from object *o*. Returns the attribute 637db96d56Sopenharmony_ci value on success, or ``NULL`` on failure. This is the equivalent of the Python 647db96d56Sopenharmony_ci expression ``o.attr_name``. 657db96d56Sopenharmony_ci 667db96d56Sopenharmony_ci 677db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_GenericGetAttr(PyObject *o, PyObject *name) 687db96d56Sopenharmony_ci 697db96d56Sopenharmony_ci Generic attribute getter function that is meant to be put into a type 707db96d56Sopenharmony_ci object's ``tp_getattro`` slot. It looks for a descriptor in the dictionary 717db96d56Sopenharmony_ci of classes in the object's MRO as well as an attribute in the object's 727db96d56Sopenharmony_ci :attr:`~object.__dict__` (if present). As outlined in :ref:`descriptors`, 737db96d56Sopenharmony_ci data descriptors take preference over instance attributes, while non-data 747db96d56Sopenharmony_ci descriptors don't. Otherwise, an :exc:`AttributeError` is raised. 757db96d56Sopenharmony_ci 767db96d56Sopenharmony_ci 777db96d56Sopenharmony_ci.. c:function:: int PyObject_SetAttr(PyObject *o, PyObject *attr_name, PyObject *v) 787db96d56Sopenharmony_ci 797db96d56Sopenharmony_ci Set the value of the attribute named *attr_name*, for object *o*, to the value 807db96d56Sopenharmony_ci *v*. Raise an exception and return ``-1`` on failure; 817db96d56Sopenharmony_ci return ``0`` on success. This is the equivalent of the Python statement 827db96d56Sopenharmony_ci ``o.attr_name = v``. 837db96d56Sopenharmony_ci 847db96d56Sopenharmony_ci If *v* is ``NULL``, the attribute is deleted. This behaviour is deprecated 857db96d56Sopenharmony_ci in favour of using :c:func:`PyObject_DelAttr`, but there are currently no 867db96d56Sopenharmony_ci plans to remove it. 877db96d56Sopenharmony_ci 887db96d56Sopenharmony_ci 897db96d56Sopenharmony_ci.. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v) 907db96d56Sopenharmony_ci 917db96d56Sopenharmony_ci Set the value of the attribute named *attr_name*, for object *o*, to the value 927db96d56Sopenharmony_ci *v*. Raise an exception and return ``-1`` on failure; 937db96d56Sopenharmony_ci return ``0`` on success. This is the equivalent of the Python statement 947db96d56Sopenharmony_ci ``o.attr_name = v``. 957db96d56Sopenharmony_ci 967db96d56Sopenharmony_ci If *v* is ``NULL``, the attribute is deleted, but this feature is 977db96d56Sopenharmony_ci deprecated in favour of using :c:func:`PyObject_DelAttrString`. 987db96d56Sopenharmony_ci 997db96d56Sopenharmony_ci 1007db96d56Sopenharmony_ci.. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value) 1017db96d56Sopenharmony_ci 1027db96d56Sopenharmony_ci Generic attribute setter and deleter function that is meant 1037db96d56Sopenharmony_ci to be put into a type object's :c:member:`~PyTypeObject.tp_setattro` 1047db96d56Sopenharmony_ci slot. It looks for a data descriptor in the 1057db96d56Sopenharmony_ci dictionary of classes in the object's MRO, and if found it takes preference 1067db96d56Sopenharmony_ci over setting or deleting the attribute in the instance dictionary. Otherwise, the 1077db96d56Sopenharmony_ci attribute is set or deleted in the object's :attr:`~object.__dict__` (if present). 1087db96d56Sopenharmony_ci On success, ``0`` is returned, otherwise an :exc:`AttributeError` 1097db96d56Sopenharmony_ci is raised and ``-1`` is returned. 1107db96d56Sopenharmony_ci 1117db96d56Sopenharmony_ci 1127db96d56Sopenharmony_ci.. c:function:: int PyObject_DelAttr(PyObject *o, PyObject *attr_name) 1137db96d56Sopenharmony_ci 1147db96d56Sopenharmony_ci Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. 1157db96d56Sopenharmony_ci This is the equivalent of the Python statement ``del o.attr_name``. 1167db96d56Sopenharmony_ci 1177db96d56Sopenharmony_ci 1187db96d56Sopenharmony_ci.. c:function:: int PyObject_DelAttrString(PyObject *o, const char *attr_name) 1197db96d56Sopenharmony_ci 1207db96d56Sopenharmony_ci Delete attribute named *attr_name*, for object *o*. Returns ``-1`` on failure. 1217db96d56Sopenharmony_ci This is the equivalent of the Python statement ``del o.attr_name``. 1227db96d56Sopenharmony_ci 1237db96d56Sopenharmony_ci 1247db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_GenericGetDict(PyObject *o, void *context) 1257db96d56Sopenharmony_ci 1267db96d56Sopenharmony_ci A generic implementation for the getter of a ``__dict__`` descriptor. It 1277db96d56Sopenharmony_ci creates the dictionary if necessary. 1287db96d56Sopenharmony_ci 1297db96d56Sopenharmony_ci This function may also be called to get the :py:attr:`~object.__dict__` 1307db96d56Sopenharmony_ci of the object *o*. Pass ``NULL`` for *context* when calling it. 1317db96d56Sopenharmony_ci Since this function may need to allocate memory for the 1327db96d56Sopenharmony_ci dictionary, it may be more efficient to call :c:func:`PyObject_GetAttr` 1337db96d56Sopenharmony_ci when accessing an attribute on the object. 1347db96d56Sopenharmony_ci 1357db96d56Sopenharmony_ci On failure, returns ``NULL`` with an exception set. 1367db96d56Sopenharmony_ci 1377db96d56Sopenharmony_ci .. versionadded:: 3.3 1387db96d56Sopenharmony_ci 1397db96d56Sopenharmony_ci 1407db96d56Sopenharmony_ci.. c:function:: int PyObject_GenericSetDict(PyObject *o, PyObject *value, void *context) 1417db96d56Sopenharmony_ci 1427db96d56Sopenharmony_ci A generic implementation for the setter of a ``__dict__`` descriptor. This 1437db96d56Sopenharmony_ci implementation does not allow the dictionary to be deleted. 1447db96d56Sopenharmony_ci 1457db96d56Sopenharmony_ci .. versionadded:: 3.3 1467db96d56Sopenharmony_ci 1477db96d56Sopenharmony_ci 1487db96d56Sopenharmony_ci.. c:function:: PyObject** _PyObject_GetDictPtr(PyObject *obj) 1497db96d56Sopenharmony_ci 1507db96d56Sopenharmony_ci Return a pointer to :py:attr:`~object.__dict__` of the object *obj*. 1517db96d56Sopenharmony_ci If there is no ``__dict__``, return ``NULL`` without setting an exception. 1527db96d56Sopenharmony_ci 1537db96d56Sopenharmony_ci This function may need to allocate memory for the 1547db96d56Sopenharmony_ci dictionary, so it may be more efficient to call :c:func:`PyObject_GetAttr` 1557db96d56Sopenharmony_ci when accessing an attribute on the object. 1567db96d56Sopenharmony_ci 1577db96d56Sopenharmony_ci 1587db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid) 1597db96d56Sopenharmony_ci 1607db96d56Sopenharmony_ci Compare the values of *o1* and *o2* using the operation specified by *opid*, 1617db96d56Sopenharmony_ci which must be one of :const:`Py_LT`, :const:`Py_LE`, :const:`Py_EQ`, 1627db96d56Sopenharmony_ci :const:`Py_NE`, :const:`Py_GT`, or :const:`Py_GE`, corresponding to ``<``, 1637db96d56Sopenharmony_ci ``<=``, ``==``, ``!=``, ``>``, or ``>=`` respectively. This is the equivalent of 1647db96d56Sopenharmony_ci the Python expression ``o1 op o2``, where ``op`` is the operator corresponding 1657db96d56Sopenharmony_ci to *opid*. Returns the value of the comparison on success, or ``NULL`` on failure. 1667db96d56Sopenharmony_ci 1677db96d56Sopenharmony_ci 1687db96d56Sopenharmony_ci.. c:function:: int PyObject_RichCompareBool(PyObject *o1, PyObject *o2, int opid) 1697db96d56Sopenharmony_ci 1707db96d56Sopenharmony_ci Compare the values of *o1* and *o2* using the operation specified by *opid*, 1717db96d56Sopenharmony_ci which must be one of :const:`Py_LT`, :const:`Py_LE`, :const:`Py_EQ`, 1727db96d56Sopenharmony_ci :const:`Py_NE`, :const:`Py_GT`, or :const:`Py_GE`, corresponding to ``<``, 1737db96d56Sopenharmony_ci ``<=``, ``==``, ``!=``, ``>``, or ``>=`` respectively. Returns ``-1`` on error, 1747db96d56Sopenharmony_ci ``0`` if the result is false, ``1`` otherwise. This is the equivalent of the 1757db96d56Sopenharmony_ci Python expression ``o1 op o2``, where ``op`` is the operator corresponding to 1767db96d56Sopenharmony_ci *opid*. 1777db96d56Sopenharmony_ci 1787db96d56Sopenharmony_ci.. note:: 1797db96d56Sopenharmony_ci If *o1* and *o2* are the same object, :c:func:`PyObject_RichCompareBool` 1807db96d56Sopenharmony_ci will always return ``1`` for :const:`Py_EQ` and ``0`` for :const:`Py_NE`. 1817db96d56Sopenharmony_ci 1827db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_Format(PyObject *obj, PyObject *format_spec) 1837db96d56Sopenharmony_ci 1847db96d56Sopenharmony_ci Format *obj* using *format_spec*. This is equivalent to the Python 1857db96d56Sopenharmony_ci expression ``format(obj, format_spec)``. 1867db96d56Sopenharmony_ci 1877db96d56Sopenharmony_ci *format_spec* may be ``NULL``. In this case the call is equivalent 1887db96d56Sopenharmony_ci to ``format(obj)``. 1897db96d56Sopenharmony_ci Returns the formatted string on success, ``NULL`` on failure. 1907db96d56Sopenharmony_ci 1917db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_Repr(PyObject *o) 1927db96d56Sopenharmony_ci 1937db96d56Sopenharmony_ci .. index:: pair: built-in function; repr 1947db96d56Sopenharmony_ci 1957db96d56Sopenharmony_ci Compute a string representation of object *o*. Returns the string 1967db96d56Sopenharmony_ci representation on success, ``NULL`` on failure. This is the equivalent of the 1977db96d56Sopenharmony_ci Python expression ``repr(o)``. Called by the :func:`repr` built-in function. 1987db96d56Sopenharmony_ci 1997db96d56Sopenharmony_ci .. versionchanged:: 3.4 2007db96d56Sopenharmony_ci This function now includes a debug assertion to help ensure that it 2017db96d56Sopenharmony_ci does not silently discard an active exception. 2027db96d56Sopenharmony_ci 2037db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_ASCII(PyObject *o) 2047db96d56Sopenharmony_ci 2057db96d56Sopenharmony_ci .. index:: pair: built-in function; ascii 2067db96d56Sopenharmony_ci 2077db96d56Sopenharmony_ci As :c:func:`PyObject_Repr`, compute a string representation of object *o*, but 2087db96d56Sopenharmony_ci escape the non-ASCII characters in the string returned by 2097db96d56Sopenharmony_ci :c:func:`PyObject_Repr` with ``\x``, ``\u`` or ``\U`` escapes. This generates 2107db96d56Sopenharmony_ci a string similar to that returned by :c:func:`PyObject_Repr` in Python 2. 2117db96d56Sopenharmony_ci Called by the :func:`ascii` built-in function. 2127db96d56Sopenharmony_ci 2137db96d56Sopenharmony_ci .. index:: string; PyObject_Str (C function) 2147db96d56Sopenharmony_ci 2157db96d56Sopenharmony_ci 2167db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_Str(PyObject *o) 2177db96d56Sopenharmony_ci 2187db96d56Sopenharmony_ci Compute a string representation of object *o*. Returns the string 2197db96d56Sopenharmony_ci representation on success, ``NULL`` on failure. This is the equivalent of the 2207db96d56Sopenharmony_ci Python expression ``str(o)``. Called by the :func:`str` built-in function 2217db96d56Sopenharmony_ci and, therefore, by the :func:`print` function. 2227db96d56Sopenharmony_ci 2237db96d56Sopenharmony_ci .. versionchanged:: 3.4 2247db96d56Sopenharmony_ci This function now includes a debug assertion to help ensure that it 2257db96d56Sopenharmony_ci does not silently discard an active exception. 2267db96d56Sopenharmony_ci 2277db96d56Sopenharmony_ci 2287db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_Bytes(PyObject *o) 2297db96d56Sopenharmony_ci 2307db96d56Sopenharmony_ci .. index:: pair: built-in function; bytes 2317db96d56Sopenharmony_ci 2327db96d56Sopenharmony_ci Compute a bytes representation of object *o*. ``NULL`` is returned on 2337db96d56Sopenharmony_ci failure and a bytes object on success. This is equivalent to the Python 2347db96d56Sopenharmony_ci expression ``bytes(o)``, when *o* is not an integer. Unlike ``bytes(o)``, 2357db96d56Sopenharmony_ci a TypeError is raised when *o* is an integer instead of a zero-initialized 2367db96d56Sopenharmony_ci bytes object. 2377db96d56Sopenharmony_ci 2387db96d56Sopenharmony_ci 2397db96d56Sopenharmony_ci.. c:function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls) 2407db96d56Sopenharmony_ci 2417db96d56Sopenharmony_ci Return ``1`` if the class *derived* is identical to or derived from the class 2427db96d56Sopenharmony_ci *cls*, otherwise return ``0``. In case of an error, return ``-1``. 2437db96d56Sopenharmony_ci 2447db96d56Sopenharmony_ci If *cls* is a tuple, the check will be done against every entry in *cls*. 2457db96d56Sopenharmony_ci The result will be ``1`` when at least one of the checks returns ``1``, 2467db96d56Sopenharmony_ci otherwise it will be ``0``. 2477db96d56Sopenharmony_ci 2487db96d56Sopenharmony_ci If *cls* has a :meth:`~class.__subclasscheck__` method, it will be called to 2497db96d56Sopenharmony_ci determine the subclass status as described in :pep:`3119`. Otherwise, 2507db96d56Sopenharmony_ci *derived* is a subclass of *cls* if it is a direct or indirect subclass, 2517db96d56Sopenharmony_ci i.e. contained in ``cls.__mro__``. 2527db96d56Sopenharmony_ci 2537db96d56Sopenharmony_ci Normally only class objects, i.e. instances of :class:`type` or a derived 2547db96d56Sopenharmony_ci class, are considered classes. However, objects can override this by having 2557db96d56Sopenharmony_ci a :attr:`__bases__` attribute (which must be a tuple of base classes). 2567db96d56Sopenharmony_ci 2577db96d56Sopenharmony_ci 2587db96d56Sopenharmony_ci.. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) 2597db96d56Sopenharmony_ci 2607db96d56Sopenharmony_ci Return ``1`` if *inst* is an instance of the class *cls* or a subclass of 2617db96d56Sopenharmony_ci *cls*, or ``0`` if not. On error, returns ``-1`` and sets an exception. 2627db96d56Sopenharmony_ci 2637db96d56Sopenharmony_ci If *cls* is a tuple, the check will be done against every entry in *cls*. 2647db96d56Sopenharmony_ci The result will be ``1`` when at least one of the checks returns ``1``, 2657db96d56Sopenharmony_ci otherwise it will be ``0``. 2667db96d56Sopenharmony_ci 2677db96d56Sopenharmony_ci If *cls* has a :meth:`~class.__instancecheck__` method, it will be called to 2687db96d56Sopenharmony_ci determine the subclass status as described in :pep:`3119`. Otherwise, *inst* 2697db96d56Sopenharmony_ci is an instance of *cls* if its class is a subclass of *cls*. 2707db96d56Sopenharmony_ci 2717db96d56Sopenharmony_ci An instance *inst* can override what is considered its class by having a 2727db96d56Sopenharmony_ci :attr:`__class__` attribute. 2737db96d56Sopenharmony_ci 2747db96d56Sopenharmony_ci An object *cls* can override if it is considered a class, and what its base 2757db96d56Sopenharmony_ci classes are, by having a :attr:`__bases__` attribute (which must be a tuple 2767db96d56Sopenharmony_ci of base classes). 2777db96d56Sopenharmony_ci 2787db96d56Sopenharmony_ci 2797db96d56Sopenharmony_ci.. c:function:: Py_hash_t PyObject_Hash(PyObject *o) 2807db96d56Sopenharmony_ci 2817db96d56Sopenharmony_ci .. index:: pair: built-in function; hash 2827db96d56Sopenharmony_ci 2837db96d56Sopenharmony_ci Compute and return the hash value of an object *o*. On failure, return ``-1``. 2847db96d56Sopenharmony_ci This is the equivalent of the Python expression ``hash(o)``. 2857db96d56Sopenharmony_ci 2867db96d56Sopenharmony_ci .. versionchanged:: 3.2 2877db96d56Sopenharmony_ci The return type is now Py_hash_t. This is a signed integer the same size 2887db96d56Sopenharmony_ci as :c:type:`Py_ssize_t`. 2897db96d56Sopenharmony_ci 2907db96d56Sopenharmony_ci 2917db96d56Sopenharmony_ci.. c:function:: Py_hash_t PyObject_HashNotImplemented(PyObject *o) 2927db96d56Sopenharmony_ci 2937db96d56Sopenharmony_ci Set a :exc:`TypeError` indicating that ``type(o)`` is not :term:`hashable` and return ``-1``. 2947db96d56Sopenharmony_ci This function receives special treatment when stored in a ``tp_hash`` slot, 2957db96d56Sopenharmony_ci allowing a type to explicitly indicate to the interpreter that it is not 2967db96d56Sopenharmony_ci hashable. 2977db96d56Sopenharmony_ci 2987db96d56Sopenharmony_ci 2997db96d56Sopenharmony_ci.. c:function:: int PyObject_IsTrue(PyObject *o) 3007db96d56Sopenharmony_ci 3017db96d56Sopenharmony_ci Returns ``1`` if the object *o* is considered to be true, and ``0`` otherwise. 3027db96d56Sopenharmony_ci This is equivalent to the Python expression ``not not o``. On failure, return 3037db96d56Sopenharmony_ci ``-1``. 3047db96d56Sopenharmony_ci 3057db96d56Sopenharmony_ci 3067db96d56Sopenharmony_ci.. c:function:: int PyObject_Not(PyObject *o) 3077db96d56Sopenharmony_ci 3087db96d56Sopenharmony_ci Returns ``0`` if the object *o* is considered to be true, and ``1`` otherwise. 3097db96d56Sopenharmony_ci This is equivalent to the Python expression ``not o``. On failure, return 3107db96d56Sopenharmony_ci ``-1``. 3117db96d56Sopenharmony_ci 3127db96d56Sopenharmony_ci 3137db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_Type(PyObject *o) 3147db96d56Sopenharmony_ci 3157db96d56Sopenharmony_ci .. index:: pair: built-in function; type 3167db96d56Sopenharmony_ci 3177db96d56Sopenharmony_ci When *o* is non-``NULL``, returns a type object corresponding to the object type 3187db96d56Sopenharmony_ci of object *o*. On failure, raises :exc:`SystemError` and returns ``NULL``. This 3197db96d56Sopenharmony_ci is equivalent to the Python expression ``type(o)``. This function increments the 3207db96d56Sopenharmony_ci reference count of the return value. There's really no reason to use this 3217db96d56Sopenharmony_ci function instead of the :c:func:`Py_TYPE()` function, which returns a 3227db96d56Sopenharmony_ci pointer of type :c:expr:`PyTypeObject*`, except when the incremented reference 3237db96d56Sopenharmony_ci count is needed. 3247db96d56Sopenharmony_ci 3257db96d56Sopenharmony_ci 3267db96d56Sopenharmony_ci.. c:function:: int PyObject_TypeCheck(PyObject *o, PyTypeObject *type) 3277db96d56Sopenharmony_ci 3287db96d56Sopenharmony_ci Return non-zero if the object *o* is of type *type* or a subtype of *type*, and 3297db96d56Sopenharmony_ci ``0`` otherwise. Both parameters must be non-``NULL``. 3307db96d56Sopenharmony_ci 3317db96d56Sopenharmony_ci 3327db96d56Sopenharmony_ci.. c:function:: Py_ssize_t PyObject_Size(PyObject *o) 3337db96d56Sopenharmony_ci Py_ssize_t PyObject_Length(PyObject *o) 3347db96d56Sopenharmony_ci 3357db96d56Sopenharmony_ci .. index:: pair: built-in function; len 3367db96d56Sopenharmony_ci 3377db96d56Sopenharmony_ci Return the length of object *o*. If the object *o* provides either the sequence 3387db96d56Sopenharmony_ci and mapping protocols, the sequence length is returned. On error, ``-1`` is 3397db96d56Sopenharmony_ci returned. This is the equivalent to the Python expression ``len(o)``. 3407db96d56Sopenharmony_ci 3417db96d56Sopenharmony_ci 3427db96d56Sopenharmony_ci.. c:function:: Py_ssize_t PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) 3437db96d56Sopenharmony_ci 3447db96d56Sopenharmony_ci Return an estimated length for the object *o*. First try to return its 3457db96d56Sopenharmony_ci actual length, then an estimate using :meth:`~object.__length_hint__`, and 3467db96d56Sopenharmony_ci finally return the default value. On error return ``-1``. This is the 3477db96d56Sopenharmony_ci equivalent to the Python expression ``operator.length_hint(o, defaultvalue)``. 3487db96d56Sopenharmony_ci 3497db96d56Sopenharmony_ci .. versionadded:: 3.4 3507db96d56Sopenharmony_ci 3517db96d56Sopenharmony_ci 3527db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_GetItem(PyObject *o, PyObject *key) 3537db96d56Sopenharmony_ci 3547db96d56Sopenharmony_ci Return element of *o* corresponding to the object *key* or ``NULL`` on failure. 3557db96d56Sopenharmony_ci This is the equivalent of the Python expression ``o[key]``. 3567db96d56Sopenharmony_ci 3577db96d56Sopenharmony_ci 3587db96d56Sopenharmony_ci.. c:function:: int PyObject_SetItem(PyObject *o, PyObject *key, PyObject *v) 3597db96d56Sopenharmony_ci 3607db96d56Sopenharmony_ci Map the object *key* to the value *v*. Raise an exception and 3617db96d56Sopenharmony_ci return ``-1`` on failure; return ``0`` on success. This is the 3627db96d56Sopenharmony_ci equivalent of the Python statement ``o[key] = v``. This function *does 3637db96d56Sopenharmony_ci not* steal a reference to *v*. 3647db96d56Sopenharmony_ci 3657db96d56Sopenharmony_ci 3667db96d56Sopenharmony_ci.. c:function:: int PyObject_DelItem(PyObject *o, PyObject *key) 3677db96d56Sopenharmony_ci 3687db96d56Sopenharmony_ci Remove the mapping for the object *key* from the object *o*. Return ``-1`` 3697db96d56Sopenharmony_ci on failure. This is equivalent to the Python statement ``del o[key]``. 3707db96d56Sopenharmony_ci 3717db96d56Sopenharmony_ci 3727db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_Dir(PyObject *o) 3737db96d56Sopenharmony_ci 3747db96d56Sopenharmony_ci This is equivalent to the Python expression ``dir(o)``, returning a (possibly 3757db96d56Sopenharmony_ci empty) list of strings appropriate for the object argument, or ``NULL`` if there 3767db96d56Sopenharmony_ci was an error. If the argument is ``NULL``, this is like the Python ``dir()``, 3777db96d56Sopenharmony_ci returning the names of the current locals; in this case, if no execution frame 3787db96d56Sopenharmony_ci is active then ``NULL`` is returned but :c:func:`PyErr_Occurred` will return false. 3797db96d56Sopenharmony_ci 3807db96d56Sopenharmony_ci 3817db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_GetIter(PyObject *o) 3827db96d56Sopenharmony_ci 3837db96d56Sopenharmony_ci This is equivalent to the Python expression ``iter(o)``. It returns a new 3847db96d56Sopenharmony_ci iterator for the object argument, or the object itself if the object is already 3857db96d56Sopenharmony_ci an iterator. Raises :exc:`TypeError` and returns ``NULL`` if the object cannot be 3867db96d56Sopenharmony_ci iterated. 3877db96d56Sopenharmony_ci 3887db96d56Sopenharmony_ci 3897db96d56Sopenharmony_ci.. c:function:: PyObject* PyObject_GetAIter(PyObject *o) 3907db96d56Sopenharmony_ci 3917db96d56Sopenharmony_ci This is the equivalent to the Python expression ``aiter(o)``. Takes an 3927db96d56Sopenharmony_ci :class:`AsyncIterable` object and returns an :class:`AsyncIterator` for it. 3937db96d56Sopenharmony_ci This is typically a new iterator but if the argument is an 3947db96d56Sopenharmony_ci :class:`AsyncIterator`, this returns itself. Raises :exc:`TypeError` and 3957db96d56Sopenharmony_ci returns ``NULL`` if the object cannot be iterated. 3967db96d56Sopenharmony_ci 3977db96d56Sopenharmony_ci .. versionadded:: 3.10 398