Special Methods for Types

This section describes the C data structures used to implement types. This is an advanced topic and the presentation here is only intended to be a quick reference.

Types are defined by a structure with the following fields. Many of the fields in this structures use typedef names such as hashfunc, binaryfunc, intargfunc, and so forth. These types are defined later in this appendix in Table B.26.

 typedef struct _typeobject { PyObject_VAR_HEAD char *tp_name; int tp_basicsize; int tp_itemsize; destructor tp_dealloc; printfunc tp_print; getattrfunc tp_getattr; setattrfunc tp_setattr; cmpfunc tp_compare; reprfunc tp_repr; PyNumberMethods *tp_as_number; PySequenceMethods *tp_as_sequence; PyMappingMethods *tp_as_mapping; hashfunc ...

Get Python Essential Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.