chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1b054aae-ffa9-4f65-8881-7f68ef25e7f9 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,207 | supabase-export-v2 | 689b103ea0de1328 | PyNumberMethods *tp_as_number; PySequenceMethods *tp_as_sequence; PyMappingMethods *tp_as_mapping;
If you wish your object to be able to act like a number, a sequence, or a
mapping object, then you place the address of a structure that implements the C
type :c:type:`PyNumberMethods`, :c:type:`PySequenceMethods`, or
:c:... | trusted_official_docs | CPython Docs | PyNumberMethods *tp_as_number; PySequenceMethods *tp_as_sequence; PyMappingMethods *tp_as_mapping;
If you wish your object to be able to act like a number, a sequence, or a
mapping object, then you place the address of a structure that implements the C
type :c:type:`PyNumberMethods`, :c:type:`PySequenceMethods`, or
:c:... | PyNumberMethods *tp_as_number; PySequenceMethods *tp_as_sequence; PyMappingMethods *tp_as_mapping;
If you wish your object to be able to act like a number, a sequence, or a
mapping object, then you place the address of a structure that implements the C
type :c:type:`PyNumberMethods`, :c:type:`PySequenceMethods`, or
:c:... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1c36f810-730b-4443-a18d-a85d64777b12 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,179 | supabase-export-v2 | 62d7a949d27bdab3 | char *ml_name; /* method name */ PyCFunction ml_meth; /* implementation function */ int ml_flags; /* flags */ const char *ml_doc; /* docstring */ } PyMethodDef;
One entry should be defined for each method provided by the type; no entries are
needed for methods inherited from a base type. One additional entry is needed
... | trusted_official_docs | CPython Docs | char *ml_name; /* method name */ PyCFunction ml_meth; /* implementation function */ int ml_flags; /* flags */ const char *ml_doc; /* docstring */ } PyMethodDef;
One entry should be defined for each method provided by the type; no entries are
needed for methods inherited from a base type. One additional entry is needed
... | char *ml_name; /* method name */ PyCFunction ml_meth; /* implementation function */ int ml_flags; /* flags */ const char *ml_doc; /* docstring */ } PyMethodDef;
One entry should be defined for each method provided by the type; no entries are
needed for methods inherited from a base type. One additional entry is needed
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1ce37227-c990-4c16-bd45-2706718c0637 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,172 | supabase-export-v2 | 68eeaebfc066c013 | #. The name of the attributes must be known when :c:func:`PyType_Ready` is called.
#. No special processing is needed to record that an attribute was looked up or
set, nor do actions need to be taken based on the value. | trusted_official_docs | CPython Docs | #. The name of the attributes must be known when :c:func:`PyType_Ready` is called.
#. No special processing is needed to record that an attribute was looked up or
set, nor do actions need to be taken based on the value. | #. The name of the attributes must be known when :c:func:`PyType_Ready` is called.
#. No special processing is needed to record that an attribute was looked up or
set, nor do actions need to be taken based on the value. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
21ca1bae-2379-414f-be11-b0a22d96b18b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,124 | supabase-export-v2 | 501d6ebb0c232022 | This section aims to give a quick fly-by on the various type methods you can implement and what they do.
Here is the definition of :c:type:`PyTypeObject`, with some fields only used in
:ref:`debug builds <debug-build>` omitted: | trusted_official_docs | CPython Docs | This section aims to give a quick fly-by on the various type methods you can implement and what they do.
Here is the definition of :c:type:`PyTypeObject`, with some fields only used in
:ref:`debug builds <debug-build>` omitted: | This section aims to give a quick fly-by on the various type methods you can implement and what they do.
Here is the definition of :c:type:`PyTypeObject`, with some fields only used in
:ref:`debug builds <debug-build>` omitted: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
25109ce8-9812-4187-8b44-a752d9c8690b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,151 | supabase-export-v2 | e09efe4a042b095d | call to a non-trivial object or API (as in the example above) might end up calling :c:member:`~PyTypeObject.tp_dealloc` again, causing a double free and a crash.
Starting with Python 3.4, it is recommended not to put any complex
finalization code in :c:member:`~PyTypeObject.tp_dealloc`, and instead use the new
:c:mem... | trusted_official_docs | CPython Docs | call to a non-trivial object or API (as in the example above) might end up calling :c:member:`~PyTypeObject.tp_dealloc` again, causing a double free and a crash.
Starting with Python 3.4, it is recommended not to put any complex
finalization code in :c:member:`~PyTypeObject.tp_dealloc`, and instead use the new
:c:mem... | call to a non-trivial object or API (as in the example above) might end up calling :c:member:`~PyTypeObject.tp_dealloc` again, causing a double free and a crash.
Starting with Python 3.4, it is recommended not to put any complex
finalization code in :c:member:`~PyTypeObject.tp_dealloc`, and instead use the new
:c:mem... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
255e2f36-db5d-4f30-9db2-0331c5bd346d | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,235 | supabase-export-v2 | ceb3d1d06319ae17 | static PyTypeObject TrivialType = { PyVarObject_HEAD_INIT(NULL, 0) /* ... other members omitted for brevity ... */ .tp_flags = Py_TPFLAGS_MANAGED_WEAKREF | ..., };
The only further addition is that ``tp_dealloc`` needs to clear any weak
references (by calling :c:func:`PyObject_ClearWeakRefs`):: | trusted_official_docs | CPython Docs | static PyTypeObject TrivialType = { PyVarObject_HEAD_INIT(NULL, 0) /* ... other members omitted for brevity ... */ .tp_flags = Py_TPFLAGS_MANAGED_WEAKREF | ..., };
The only further addition is that ``tp_dealloc`` needs to clear any weak
references (by calling :c:func:`PyObject_ClearWeakRefs`):: | static PyTypeObject TrivialType = { PyVarObject_HEAD_INIT(NULL, 0) /* ... other members omitted for brevity ... */ .tp_flags = Py_TPFLAGS_MANAGED_WEAKREF | ..., };
The only further addition is that ``tp_dealloc`` needs to clear any weak
references (by calling :c:func:`PyObject_ClearWeakRefs`):: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
28e1ce4b-de1a-4a75-9c44-23c3fcd5ba34 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,200 | supabase-export-v2 | 93cd53162e47e0cf | newdatatype_richcmp(PyObject *lhs, PyObject *rhs, int op) { newdatatypeobject *obj1 = (newdatatypeobject *) lhs; newdatatypeobject *obj2 = (newdatatypeobject *) rhs; PyObject *result; int c, size1, size2;
/* code to make sure that both arguments are of type
newdatatype omitted */ | trusted_official_docs | CPython Docs | newdatatype_richcmp(PyObject *lhs, PyObject *rhs, int op) { newdatatypeobject *obj1 = (newdatatypeobject *) lhs; newdatatypeobject *obj2 = (newdatatypeobject *) rhs; PyObject *result; int c, size1, size2;
/* code to make sure that both arguments are of type
newdatatype omitted */ | newdatatype_richcmp(PyObject *lhs, PyObject *rhs, int op) { newdatatypeobject *obj1 = (newdatatypeobject *) lhs; newdatatypeobject *obj2 = (newdatatypeobject *) rhs; PyObject *result; int c, size1, size2;
/* code to make sure that both arguments are of type
newdatatype omitted */ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
29db511a-2068-4815-985d-f8bd26e41b2b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,175 | supabase-export-v2 | 92cecc5671cde7c7 | that are inherited from their base type, and should leave the :c:member:`~PyTypeObject.tp_getattro` and :c:member:`~PyTypeObject.tp_setattro` fields ``NULL`` as well, allowing the base type to handle attributes.
The tables are declared as three fields of the type object:: | trusted_official_docs | CPython Docs | that are inherited from their base type, and should leave the :c:member:`~PyTypeObject.tp_getattro` and :c:member:`~PyTypeObject.tp_setattro` fields ``NULL`` as well, allowing the base type to handle attributes.
The tables are declared as three fields of the type object:: | that are inherited from their base type, and should leave the :c:member:`~PyTypeObject.tp_getattro` and :c:member:`~PyTypeObject.tp_setattro` fields ``NULL`` as well, allowing the base type to handle attributes.
The tables are declared as three fields of the type object:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2e5fe322-9300-497c-8252-3db19e4210be | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,141 | supabase-export-v2 | a795ce36f812eb07 | If your type supports garbage collection, the destructor should call :c:func:`PyObject_GC_UnTrack` before clearing any member fields::
static void
newdatatype_dealloc(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
PyObject_GC_UnTrack(op);
Py_CLEAR(self->other_obj);
... Py_TYPE(self)->tp_free(... | trusted_official_docs | CPython Docs | If your type supports garbage collection, the destructor should call :c:func:`PyObject_GC_UnTrack` before clearing any member fields::
static void
newdatatype_dealloc(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
PyObject_GC_UnTrack(op);
Py_CLEAR(self->other_obj);
... Py_TYPE(self)->tp_free(... | If your type supports garbage collection, the destructor should call :c:func:`PyObject_GC_UnTrack` before clearing any member fields::
static void
newdatatype_dealloc(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
PyObject_GC_UnTrack(op);
Py_CLEAR(self->other_obj);
... Py_TYPE(self)->tp_free(... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
37c60393-fef4-4d73-a184-0a0429b5fb0f | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,165 | supabase-export-v2 | 937120de53205917 | set attributes (if setting attributes is allowed). Removing an attribute is a special case, for which the new value passed to the handler is ``NULL``.
Python supports two pairs of attribute handlers; a type that supports attributes
only needs to implement the functions for one pair. The difference is that one
pair take... | trusted_official_docs | CPython Docs | set attributes (if setting attributes is allowed). Removing an attribute is a special case, for which the new value passed to the handler is ``NULL``.
Python supports two pairs of attribute handlers; a type that supports attributes
only needs to implement the functions for one pair. The difference is that one
pair take... | set attributes (if setting attributes is allowed). Removing an attribute is a special case, for which the new value passed to the handler is ``NULL``.
Python supports two pairs of attribute handlers; a type that supports attributes
only needs to implement the functions for one pair. The difference is that one
pair take... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3ed1fd66-5ca2-4ccd-8995-ac565fb1e83b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,184 | supabase-export-v2 | 93985d279bd0e1dd | table. An application can use the introspection API to retrieve the descriptor from the class object, and get the doc string using its :attr:`~type.__doc__` attribute.
As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value
of ``NULL`` is required. | trusted_official_docs | CPython Docs | table. An application can use the introspection API to retrieve the descriptor from the class object, and get the doc string using its :attr:`~type.__doc__` attribute.
As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value
of ``NULL`` is required. | table. An application can use the introspection API to retrieve the descriptor from the class object, and get the doc string using its :attr:`~type.__doc__` attribute.
As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value
of ``NULL`` is required. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
409308cf-c246-4f37-9c93-1d5971c56633 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,214 | supabase-export-v2 | 712ba032ac4e73f5 | type is "called", for example, if ``obj1`` is an instance of your data type and the Python script contains ``obj1('hello')``, the :c:member:`~PyTypeObject.tp_call` handler is invoked.
This function takes three arguments: | trusted_official_docs | CPython Docs | type is "called", for example, if ``obj1`` is an instance of your data type and the Python script contains ``obj1('hello')``, the :c:member:`~PyTypeObject.tp_call` handler is invoked.
This function takes three arguments: | type is "called", for example, if ``obj1`` is an instance of your data type and the Python script contains ``obj1('hello')``, the :c:member:`~PyTypeObject.tp_call` handler is invoked.
This function takes three arguments: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4565b441-8779-484c-9e69-b78efebad448 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,127 | supabase-export-v2 | ba0af3c1b7e9a366 | though -- if you have a type you want to define, the chances are very good that you will only implement a handful of these.
As you probably expect by now, we're going to go over this and give more
information about the various handlers. We won't go in the order they are
defined in the structure, because there is a lot ... | trusted_official_docs | CPython Docs | though -- if you have a type you want to define, the chances are very good that you will only implement a handful of these.
As you probably expect by now, we're going to go over this and give more
information about the various handlers. We won't go in the order they are
defined in the structure, because there is a lot ... | though -- if you have a type you want to define, the chances are very good that you will only implement a handful of these.
As you probably expect by now, we're going to go over this and give more
information about the various handlers. We won't go in the order they are
defined in the structure, because there is a lot ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4615bbbe-12c0-42b7-bebd-ab1f40981bc1 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,167 | supabase-export-v2 | c31e8581f3efe576 | getattrfunc tp_getattr; /* char * version */ setattrfunc tp_setattr; /* ... */ getattrofunc tp_getattro; /* PyObject * version */ setattrofunc tp_setattro;
If accessing attributes of an object is always a simple operation (this will be
explained shortly), there are generic implementations which can be used to
provide t... | trusted_official_docs | CPython Docs | getattrfunc tp_getattr; /* char * version */ setattrfunc tp_setattr; /* ... */ getattrofunc tp_getattro; /* PyObject * version */ setattrofunc tp_setattro;
If accessing attributes of an object is always a simple operation (this will be
explained shortly), there are generic implementations which can be used to
provide t... | getattrfunc tp_getattr; /* char * version */ setattrfunc tp_setattr; /* ... */ getattrofunc tp_getattro; /* PyObject * version */ setattrofunc tp_setattro;
If accessing attributes of an object is always a simple operation (this will be
explained shortly), there are generic implementations which can be used to
provide t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4696230a-9afa-4a86-b3e6-4e502c38ac1e | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,182 | supabase-export-v2 | caab634ebf8587bf | typedef struct PyMemberDef { const char *name; int type; int offset; int flags; const char *doc; } PyMemberDef;
For each entry in the table, a :term:`descriptor` will be constructed and added to the
type which will be able to extract a value from the instance structure. The
:c:member:`~PyMemberDef.type` field should co... | trusted_official_docs | CPython Docs | typedef struct PyMemberDef { const char *name; int type; int offset; int flags; const char *doc; } PyMemberDef;
For each entry in the table, a :term:`descriptor` will be constructed and added to the
type which will be able to extract a value from the instance structure. The
:c:member:`~PyMemberDef.type` field should co... | typedef struct PyMemberDef { const char *name; int type; int offset; int flags; const char *doc; } PyMemberDef;
For each entry in the table, a :term:`descriptor` will be constructed and added to the
type which will be able to extract a value from the instance structure. The
:c:member:`~PyMemberDef.type` field should co... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
46b569e6-be82-4426-9940-22795b5ab924 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,229 | supabase-export-v2 | b1dc1bca3db238e1 | Weak Reference Support ----------------------
One of the goals of Python's weak reference implementation is to allow any type
to participate in the weak reference mechanism without incurring the overhead on
performance-critical objects (such as numbers). | trusted_official_docs | CPython Docs | Weak Reference Support ----------------------
One of the goals of Python's weak reference implementation is to allow any type
to participate in the weak reference mechanism without incurring the overhead on
performance-critical objects (such as numbers). | Weak Reference Support ----------------------
One of the goals of Python's weak reference implementation is to allow any type
to participate in the weak reference mechanism without incurring the overhead on
performance-critical objects (such as numbers). | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
479c1b5b-9401-4ed2-8347-dd1a1b028c27 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,206 | supabase-export-v2 | df65c48c896a280f | the slot values are non-``NULL``. The flag may be set to indicate the presence of a slot, but a slot may still be unfilled.) ::
PyNumberMethods *tp_as_number;
PySequenceMethods *tp_as_sequence;
PyMappingMethods *tp_as_mapping; | trusted_official_docs | CPython Docs | the slot values are non-``NULL``. The flag may be set to indicate the presence of a slot, but a slot may still be unfilled.) ::
PyNumberMethods *tp_as_number;
PySequenceMethods *tp_as_sequence;
PyMappingMethods *tp_as_mapping; | the slot values are non-``NULL``. The flag may be set to indicate the presence of a slot, but a slot may still be unfilled.) ::
PyNumberMethods *tp_as_number;
PySequenceMethods *tp_as_sequence;
PyMappingMethods *tp_as_mapping; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
495ad60d-690a-4a37-b05b-340c921a9644 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,174 | supabase-export-v2 | eb8a5e90fedd296c | that this list does not place any restrictions on the values of the attributes, when the values are computed, or how relevant data is stored.
When :c:func:`PyType_Ready` is called, it uses three tables referenced by the
type object to create :term:`descriptor`\s which are placed in the dictionary of the
type object. Ea... | trusted_official_docs | CPython Docs | that this list does not place any restrictions on the values of the attributes, when the values are computed, or how relevant data is stored.
When :c:func:`PyType_Ready` is called, it uses three tables referenced by the
type object to create :term:`descriptor`\s which are placed in the dictionary of the
type object. Ea... | that this list does not place any restrictions on the values of the attributes, when the values are computed, or how relevant data is stored.
When :c:func:`PyType_Ready` is called, it uses three tables referenced by the
type object to create :term:`descriptor`\s which are placed in the dictionary of the
type object. Ea... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4a11dc8e-9e20-4300-b989-963435f59f3a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,205 | supabase-export-v2 | 5e7c0aef1c76b2f1 | Python supports a variety of *abstract* 'protocols;' the specific interfaces provided to use these interfaces are documented in :ref:`abstract`.
A number of these abstract interfaces were defined early in the development of
the Python implementation. In particular, the number, mapping, and sequence
protocols have been ... | trusted_official_docs | CPython Docs | Python supports a variety of *abstract* 'protocols;' the specific interfaces provided to use these interfaces are documented in :ref:`abstract`.
A number of these abstract interfaces were defined early in the development of
the Python implementation. In particular, the number, mapping, and sequence
protocols have been ... | Python supports a variety of *abstract* 'protocols;' the specific interfaces provided to use these interfaces are documented in :ref:`abstract`.
A number of these abstract interfaces were defined early in the development of
the Python implementation. In particular, the number, mapping, and sequence
protocols have been ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
50dcfd0a-306d-4925-a4eb-e05365482b34 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,215 | supabase-export-v2 | 7905ff16fb1081e5 | This function takes three arguments:
#. *self* is the instance of the data type which is the subject of the call. If the call is ``obj1('hello')``, then *self* is ``obj1``. | trusted_official_docs | CPython Docs | This function takes three arguments:
#. *self* is the instance of the data type which is the subject of the call. If the call is ``obj1('hello')``, then *self* is ``obj1``. | This function takes three arguments:
#. *self* is the instance of the data type which is the subject of the call. If the call is ``obj1('hello')``, then *self* is ``obj1``. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
549adc5e-de72-4214-aa65-5e0a3c905d92 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,186 | supabase-export-v2 | f17b59ead9786096 | .. XXX Descriptors need to be explained in more detail somewhere, but not here.
Descriptor objects have two handler functions which correspond to the
\member{tp_getattro} and \member{tp_setattro} handlers. The
\method{__get__()} handler is a function which is passed the descriptor,
instance, and type objects, and re... | trusted_official_docs | CPython Docs | .. XXX Descriptors need to be explained in more detail somewhere, but not here.
Descriptor objects have two handler functions which correspond to the
\member{tp_getattro} and \member{tp_setattro} handlers. The
\method{__get__()} handler is a function which is passed the descriptor,
instance, and type objects, and re... | .. XXX Descriptors need to be explained in more detail somewhere, but not here.
Descriptor objects have two handler functions which correspond to the
\member{tp_getattro} and \member{tp_setattro} handlers. The
\method{__get__()} handler is a function which is passed the descriptor,
instance, and type objects, and re... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
54d353d8-9362-4da9-8169-f110ab6d3db9 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,173 | supabase-export-v2 | 5bd419cce082cd7e | special processing is needed to record that an attribute was looked up or set, nor do actions need to be taken based on the value.
Note that this list does not place any restrictions on the values of the
attributes, when the values are computed, or how relevant data is stored. | trusted_official_docs | CPython Docs | special processing is needed to record that an attribute was looked up or set, nor do actions need to be taken based on the value.
Note that this list does not place any restrictions on the values of the
attributes, when the values are computed, or how relevant data is stored. | special processing is needed to record that an attribute was looked up or set, nor do actions need to be taken based on the value.
Note that this list does not place any restrictions on the values of the
attributes, when the values are computed, or how relevant data is stored. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
583a3189-3c6f-4d46-863b-cbc5ca5e9ccf | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,199 | supabase-export-v2 | e3627d989a3ab953 | Here is a sample implementation, for a datatype that is considered equal if the size of an internal pointer is equal::
static PyObject *
newdatatype_richcmp(PyObject *lhs, PyObject *rhs, int op)
{
newdatatypeobject *obj1 = (newdatatypeobject *) lhs;
newdatatypeobject *obj2 = (newdatatypeobject *) rhs;
PyObject *re... | trusted_official_docs | CPython Docs | Here is a sample implementation, for a datatype that is considered equal if the size of an internal pointer is equal::
static PyObject *
newdatatype_richcmp(PyObject *lhs, PyObject *rhs, int op)
{
newdatatypeobject *obj1 = (newdatatypeobject *) lhs;
newdatatypeobject *obj2 = (newdatatypeobject *) rhs;
PyObject *re... | Here is a sample implementation, for a datatype that is considered equal if the size of an internal pointer is equal::
static PyObject *
newdatatype_richcmp(PyObject *lhs, PyObject *rhs, int op)
{
newdatatypeobject *obj1 = (newdatatypeobject *) lhs;
newdatatypeobject *obj2 = (newdatatypeobject *) rhs;
PyObject *re... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5a5beded-c04e-4985-86bd-28d670ab3e4d | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,161 | supabase-export-v2 | dfa53dbd2959e4d5 | similar to the :c:member:`~PyTypeObject.tp_repr` function, but the resulting string is intended for human consumption. If :c:member:`~PyTypeObject.tp_str` is not specified, the :c:member:`~PyTypeObject.tp_repr` handler is used instead.
Here is a simple example:: | trusted_official_docs | CPython Docs | similar to the :c:member:`~PyTypeObject.tp_repr` function, but the resulting string is intended for human consumption. If :c:member:`~PyTypeObject.tp_str` is not specified, the :c:member:`~PyTypeObject.tp_repr` handler is used instead.
Here is a simple example:: | similar to the :c:member:`~PyTypeObject.tp_repr` function, but the resulting string is intended for human consumption. If :c:member:`~PyTypeObject.tp_str` is not specified, the :c:member:`~PyTypeObject.tp_repr` handler is used instead.
Here is a simple example:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5e92139a-69bb-4d32-834e-37875f335a05 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,155 | supabase-export-v2 | 4631bfe8540332ff | Object Presentation -------------------
In Python, there are two ways to generate a textual representation of an object:
the :func:`repr` function, and the :func:`str` function. (The :func:`print`
function just calls :func:`str`.) These handlers are both optional. | trusted_official_docs | CPython Docs | Object Presentation -------------------
In Python, there are two ways to generate a textual representation of an object:
the :func:`repr` function, and the :func:`str` function. (The :func:`print`
function just calls :func:`str`.) These handlers are both optional. | Object Presentation -------------------
In Python, there are two ways to generate a textual representation of an object:
the :func:`repr` function, and the :func:`str` function. (The :func:`print`
function just calls :func:`str`.) These handlers are both optional. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5f75664f-4a69-4765-8bef-dc0a4382ad8e | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,129 | supabase-export-v2 | 5c8871976171a357 | const char *tp_name; /* For printing */
The name of the type -- as mentioned in the previous chapter, this will appear in
various places, almost entirely for diagnostic purposes. Try to choose something
that will be helpful in such a situation! :: | trusted_official_docs | CPython Docs | const char *tp_name; /* For printing */
The name of the type -- as mentioned in the previous chapter, this will appear in
various places, almost entirely for diagnostic purposes. Try to choose something
that will be helpful in such a situation! :: | const char *tp_name; /* For printing */
The name of the type -- as mentioned in the previous chapter, this will appear in
various places, almost entirely for diagnostic purposes. Try to choose something
that will be helpful in such a situation! :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
600fffc8-9b34-41eb-971e-154324406f73 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,185 | supabase-export-v2 | e4482b172830f780 | As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value of ``NULL`` is required.
.. XXX Descriptors need to be explained in more detail somewhere, but not here. | trusted_official_docs | CPython Docs | As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value of ``NULL`` is required.
.. XXX Descriptors need to be explained in more detail somewhere, but not here. | As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.ml_name` value of ``NULL`` is required.
.. XXX Descriptors need to be explained in more detail somewhere, but not here. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6507c860-6b5b-4d70-9ce0-5ffdb4e008e3 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,180 | supabase-export-v2 | ba71cc6fd7349dc6 | is needed at the end; it is a sentinel that marks the end of the array. The :c:member:`~PyMethodDef.ml_name` field of the sentinel must be ``NULL``.
The second table is used to define attributes which map directly to data stored
in the instance. A variety of primitive C types are supported, and access may
be read-only ... | trusted_official_docs | CPython Docs | is needed at the end; it is a sentinel that marks the end of the array. The :c:member:`~PyMethodDef.ml_name` field of the sentinel must be ``NULL``.
The second table is used to define attributes which map directly to data stored
in the instance. A variety of primitive C types are supported, and access may
be read-only ... | is needed at the end; it is a sentinel that marks the end of the array. The :c:member:`~PyMethodDef.ml_name` field of the sentinel must be ``NULL``.
The second table is used to define attributes which map directly to data stored
in the instance. A variety of primitive C types are supported, and access may
be read-only ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
67fcb99a-4019-4e6a-bc2c-9e53b5eacd3a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,223 | supabase-export-v2 | 41e659866c987243 | /* Iterators */ getiterfunc tp_iter; iternextfunc tp_iternext;
These functions provide support for the iterator protocol. Both handlers
take exactly one parameter, the instance for which they are being called,
and return a new reference. In the case of an error, they should set an
exception and return ``NULL``. :c:memb... | trusted_official_docs | CPython Docs | /* Iterators */ getiterfunc tp_iter; iternextfunc tp_iternext;
These functions provide support for the iterator protocol. Both handlers
take exactly one parameter, the instance for which they are being called,
and return a new reference. In the case of an error, they should set an
exception and return ``NULL``. :c:memb... | /* Iterators */ getiterfunc tp_iter; iternextfunc tp_iternext;
These functions provide support for the iterator protocol. Both handlers
take exactly one parameter, the instance for which they are being called,
and return a new reference. In the case of an error, they should set an
exception and return ``NULL``. :c:memb... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6956c3b0-9b39-410c-8e51-49ddf7a3468c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,232 | supabase-export-v2 | 445f6fb0d49eb53e | to be weakly referenceable, the extension type must set the ``Py_TPFLAGS_MANAGED_WEAKREF`` bit of the :c:member:`~PyTypeObject.tp_flags` field. The legacy :c:member:`~PyTypeObject.tp_weaklistoffset` field should be left as zero.
If this flag is set, :c:macro:`Py_TPFLAGS_HAVE_GC` should also be set. | trusted_official_docs | CPython Docs | to be weakly referenceable, the extension type must set the ``Py_TPFLAGS_MANAGED_WEAKREF`` bit of the :c:member:`~PyTypeObject.tp_flags` field. The legacy :c:member:`~PyTypeObject.tp_weaklistoffset` field should be left as zero.
If this flag is set, :c:macro:`Py_TPFLAGS_HAVE_GC` should also be set. | to be weakly referenceable, the extension type must set the ``Py_TPFLAGS_MANAGED_WEAKREF`` bit of the :c:member:`~PyTypeObject.tp_flags` field. The legacy :c:member:`~PyTypeObject.tp_weaklistoffset` field should be left as zero.
If this flag is set, :c:macro:`Py_TPFLAGS_HAVE_GC` should also be set. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
71840a5d-f07d-468e-bfb9-ce52109df112 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,238 | supabase-export-v2 | 1138b1d40641ea82 | More Suggestions ----------------
In order to learn how to implement any specific method for your new data type,
get the :term:`CPython` source code. Go to the :file:`Objects` directory,
then search the C source files for ``tp_`` plus the function you want
(for example, ``tp_richcompare``). You will find examples of th... | trusted_official_docs | CPython Docs | More Suggestions ----------------
In order to learn how to implement any specific method for your new data type,
get the :term:`CPython` source code. Go to the :file:`Objects` directory,
then search the C source files for ``tp_`` plus the function you want
(for example, ``tp_richcompare``). You will find examples of th... | More Suggestions ----------------
In order to learn how to implement any specific method for your new data type,
get the :term:`CPython` source code. Go to the :file:`Objects` directory,
then search the C source files for ``tp_`` plus the function you want
(for example, ``tp_richcompare``). You will find examples of th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
72b1a2fe-6215-46e6-aed2-30eaa7afaded | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,225 | supabase-export-v2 | 12d80b4d2bcb1c86 | Any :term:`iterable` object must implement the :c:member:`~PyTypeObject.tp_iter` handler, which must return an :term:`iterator` object. Here the same guidelines apply as for Python classes:
* For collections (such as lists and tuples) which can support multiple
independent iterators, a new iterator should be created a... | trusted_official_docs | CPython Docs | Any :term:`iterable` object must implement the :c:member:`~PyTypeObject.tp_iter` handler, which must return an :term:`iterator` object. Here the same guidelines apply as for Python classes:
* For collections (such as lists and tuples) which can support multiple
independent iterators, a new iterator should be created a... | Any :term:`iterable` object must implement the :c:member:`~PyTypeObject.tp_iter` handler, which must return an :term:`iterator` object. Here the same guidelines apply as for Python classes:
* For collections (such as lists and tuples) which can support multiple
independent iterators, a new iterator should be created a... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77432e3e-2dc1-4e53-9ae7-11ef4ac478c1 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,144 | supabase-export-v2 | 17f2b7a645b76cd9 | to save a pending exception before performing the unsafe action, and restoring it when done. This can be done using the :c:func:`PyErr_Fetch` and :c:func:`PyErr_Restore` functions::
static void
my_dealloc(PyObject *obj)
{
MyObject *self = (MyObject *) obj;
PyObject *cbresult; | trusted_official_docs | CPython Docs | to save a pending exception before performing the unsafe action, and restoring it when done. This can be done using the :c:func:`PyErr_Fetch` and :c:func:`PyErr_Restore` functions::
static void
my_dealloc(PyObject *obj)
{
MyObject *self = (MyObject *) obj;
PyObject *cbresult; | to save a pending exception before performing the unsafe action, and restoring it when done. This can be done using the :c:func:`PyErr_Fetch` and :c:func:`PyErr_Restore` functions::
static void
my_dealloc(PyObject *obj)
{
MyObject *self = (MyObject *) obj;
PyObject *cbresult; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
77d25a15-fcec-4c7e-b0f3-3a585cde5e13 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,183 | supabase-export-v2 | bbd502fe8e2d688d | used to store flags which control how the attribute can be accessed: you can set it to :c:macro:`Py_READONLY` to prevent Python code from setting it.
An interesting advantage of using the :c:member:`~PyTypeObject.tp_members` table to build
descriptors that are used at runtime is that any attribute defined this way can
... | trusted_official_docs | CPython Docs | used to store flags which control how the attribute can be accessed: you can set it to :c:macro:`Py_READONLY` to prevent Python code from setting it.
An interesting advantage of using the :c:member:`~PyTypeObject.tp_members` table to build
descriptors that are used at runtime is that any attribute defined this way can
... | used to store flags which control how the attribute can be accessed: you can set it to :c:macro:`Py_READONLY` to prevent Python code from setting it.
An interesting advantage of using the :c:member:`~PyTypeObject.tp_members` table to build
descriptors that are used at runtime is that any attribute defined this way can
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
82b2b243-506f-43c1-a5c9-a94e58ad0638 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,134 | supabase-export-v2 | 00e4531c267075d7 | Here you can put a string (or its address) that you want returned when the Python script references ``obj.__doc__`` to retrieve the doc string.
Now we come to the basic type methods -- the ones most extension types will
implement. | trusted_official_docs | CPython Docs | Here you can put a string (or its address) that you want returned when the Python script references ``obj.__doc__`` to retrieve the doc string.
Now we come to the basic type methods -- the ones most extension types will
implement. | Here you can put a string (or its address) that you want returned when the Python script references ``obj.__doc__`` to retrieve the doc string.
Now we come to the basic type methods -- the ones most extension types will
implement. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
892088d9-ac07-49e9-9f86-dab3aa355ded | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,194 | supabase-export-v2 | 746a40498a81a005 | Here is an example that simply raises an exception; if this were really all you wanted, the :c:member:`~PyTypeObject.tp_setattr` handler should be set to ``NULL``. ::
static int
newdatatype_setattr(PyObject *op, char *name, PyObject *v)
{
PyErr_Format(PyExc_RuntimeError, "Read-only attribute: %s", name);
return -1;... | trusted_official_docs | CPython Docs | Here is an example that simply raises an exception; if this were really all you wanted, the :c:member:`~PyTypeObject.tp_setattr` handler should be set to ``NULL``. ::
static int
newdatatype_setattr(PyObject *op, char *name, PyObject *v)
{
PyErr_Format(PyExc_RuntimeError, "Read-only attribute: %s", name);
return -1;... | Here is an example that simply raises an exception; if this were really all you wanted, the :c:member:`~PyTypeObject.tp_setattr` handler should be set to ``NULL``. ::
static int
newdatatype_setattr(PyObject *op, char *name, PyObject *v)
{
PyErr_Format(PyExc_RuntimeError, "Read-only attribute: %s", name);
return -1;... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8d4821ea-9fd8-4512-8dff-0f1e28e30038 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,138 | supabase-export-v2 | 118d20e45230cb81 | destructor tp_dealloc;
This function is called when the reference count of the instance of your type is
reduced to zero and the Python interpreter wants to reclaim it. If your type
has memory to free or other clean-up to perform, you can put it here. The
object itself needs to be freed here as well. Here is an example ... | trusted_official_docs | CPython Docs | destructor tp_dealloc;
This function is called when the reference count of the instance of your type is
reduced to zero and the Python interpreter wants to reclaim it. If your type
has memory to free or other clean-up to perform, you can put it here. The
object itself needs to be freed here as well. Here is an example ... | destructor tp_dealloc;
This function is called when the reference count of the instance of your type is
reduced to zero and the Python interpreter wants to reclaim it. If your type
has memory to free or other clean-up to perform, you can put it here. The
object itself needs to be freed here as well. Here is an example ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8f856114-3b25-42b2-9b13-7f6ff04a7c2a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,128 | supabase-export-v2 | 593ce28ec692a27d | fields. It's often easiest to find an example that includes the fields you need and then change the values to suit your new type. ::
const char *tp_name; /* For printing */ | trusted_official_docs | CPython Docs | fields. It's often easiest to find an example that includes the fields you need and then change the values to suit your new type. ::
const char *tp_name; /* For printing */ | fields. It's often easiest to find an example that includes the fields you need and then change the values to suit your new type. ::
const char *tp_name; /* For printing */ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
92d77ec6-469a-446e-8d4b-eb612eaf9bff | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,193 | supabase-export-v2 | b1cd7c1b0416d3bd | PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.400s'", Py_TYPE(self)->tp_name, name); return NULL; }
The :c:member:`~PyTypeObject.tp_setattr` handler is called when the :meth:`~object.__setattr__` or
:meth:`~object.__delattr__` method of a class instance would be called. When an
attribute shoul... | trusted_official_docs | CPython Docs | PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.400s'", Py_TYPE(self)->tp_name, name); return NULL; }
The :c:member:`~PyTypeObject.tp_setattr` handler is called when the :meth:`~object.__setattr__` or
:meth:`~object.__delattr__` method of a class instance would be called. When an
attribute shoul... | PyErr_Format(PyExc_AttributeError, "'%.100s' object has no attribute '%.400s'", Py_TYPE(self)->tp_name, name); return NULL; }
The :c:member:`~PyTypeObject.tp_setattr` handler is called when the :meth:`~object.__setattr__` or
:meth:`~object.__delattr__` method of a class instance would be called. When an
attribute shoul... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
94a7db60-5128-47e6-9168-ad012604fd9c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,158 | supabase-export-v2 | d555bbbc3c57ed75 | The :c:member:`~PyTypeObject.tp_repr` handler should return a string object containing a representation of the instance for which it is called. Here is a simple example::
static PyObject *
newdatatype_repr(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
return PyUnicode_FromFormat("Repr-ified_ne... | trusted_official_docs | CPython Docs | The :c:member:`~PyTypeObject.tp_repr` handler should return a string object containing a representation of the instance for which it is called. Here is a simple example::
static PyObject *
newdatatype_repr(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
return PyUnicode_FromFormat("Repr-ified_ne... | The :c:member:`~PyTypeObject.tp_repr` handler should return a string object containing a representation of the instance for which it is called. Here is a simple example::
static PyObject *
newdatatype_repr(PyObject *op)
{
newdatatypeobject *self = (newdatatypeobject *) op;
return PyUnicode_FromFormat("Repr-ified_ne... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9d88458b-1bc7-42c5-998a-bf707f53e46a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,181 | supabase-export-v2 | b7311c9a8fa591fe | the instance. A variety of primitive C types are supported, and access may be read-only or read-write. The structures in the table are defined as::
typedef struct PyMemberDef {
const char *name;
int type;
int offset;
int flags;
const char *doc;
} PyMemberDef; | trusted_official_docs | CPython Docs | the instance. A variety of primitive C types are supported, and access may be read-only or read-write. The structures in the table are defined as::
typedef struct PyMemberDef {
const char *name;
int type;
int offset;
int flags;
const char *doc;
} PyMemberDef; | the instance. A variety of primitive C types are supported, and access may be read-only or read-write. The structures in the table are defined as::
typedef struct PyMemberDef {
const char *name;
int type;
int offset;
int flags;
const char *doc;
} PyMemberDef; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a4963ff0-ef88-4698-9d9e-33629c22c800 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,224 | supabase-export-v2 | 70b7d2468df6a9c4 | an error, they should set an exception and return ``NULL``. :c:member:`~PyTypeObject.tp_iter` corresponds to the Python :meth:`~object.__iter__` method, while :c:member:`~PyTypeObject.tp_iternext` corresponds to the Python :meth:`~iterator.__next__` method.
Any :term:`iterable` object must implement the :c:member:`~PyT... | trusted_official_docs | CPython Docs | an error, they should set an exception and return ``NULL``. :c:member:`~PyTypeObject.tp_iter` corresponds to the Python :meth:`~object.__iter__` method, while :c:member:`~PyTypeObject.tp_iternext` corresponds to the Python :meth:`~iterator.__next__` method.
Any :term:`iterable` object must implement the :c:member:`~PyT... | an error, they should set an exception and return ``NULL``. :c:member:`~PyTypeObject.tp_iter` corresponds to the Python :meth:`~object.__iter__` method, while :c:member:`~PyTypeObject.tp_iternext` corresponds to the Python :meth:`~iterator.__next__` method.
Any :term:`iterable` object must implement the :c:member:`~PyT... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a9d8eb42-c1fa-48bd-bfee-5cfa7d721cf8 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,231 | supabase-export-v2 | f74da6dde3e28125 | .. seealso:: Documentation for the :mod:`weakref` module.
For an object to be weakly referenceable, the extension type must set the
``Py_TPFLAGS_MANAGED_WEAKREF`` bit of the :c:member:`~PyTypeObject.tp_flags`
field. The legacy :c:member:`~PyTypeObject.tp_weaklistoffset` field should
be left as zero. | trusted_official_docs | CPython Docs | .. seealso:: Documentation for the :mod:`weakref` module.
For an object to be weakly referenceable, the extension type must set the
``Py_TPFLAGS_MANAGED_WEAKREF`` bit of the :c:member:`~PyTypeObject.tp_flags`
field. The legacy :c:member:`~PyTypeObject.tp_weaklistoffset` field should
be left as zero. | .. seealso:: Documentation for the :mod:`weakref` module.
For an object to be weakly referenceable, the extension type must set the
``Py_TPFLAGS_MANAGED_WEAKREF`` bit of the :c:member:`~PyTypeObject.tp_flags`
field. The legacy :c:member:`~PyTypeObject.tp_weaklistoffset` field should
be left as zero. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ac9378ad-2236-4a4e-b599-35793152d9c7 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,166 | supabase-export-v2 | 45820c373ccecaf1 | the attribute as a :c:expr:`char\*`, while the other accepts a :c:expr:`PyObject*`. Each type can use whichever pair makes more sense for the implementation's convenience. ::
getattrfunc tp_getattr; /* char * version */
setattrfunc tp_setattr;
/* ... */
getattrofunc tp_getattro; /* PyObject * version */
setattrofun... | trusted_official_docs | CPython Docs | the attribute as a :c:expr:`char\*`, while the other accepts a :c:expr:`PyObject*`. Each type can use whichever pair makes more sense for the implementation's convenience. ::
getattrfunc tp_getattr; /* char * version */
setattrfunc tp_setattr;
/* ... */
getattrofunc tp_getattro; /* PyObject * version */
setattrofun... | the attribute as a :c:expr:`char\*`, while the other accepts a :c:expr:`PyObject*`. Each type can use whichever pair makes more sense for the implementation's convenience. ::
getattrfunc tp_getattr; /* char * version */
setattrfunc tp_setattr;
/* ... */
getattrofunc tp_getattro; /* PyObject * version */
setattrofun... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b1f46472-c576-41f3-a8b9-b7ed474bcbe6 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,202 | supabase-export-v2 | b763fda19347b7e5 | size1 = obj1->obj_UnderlyingDatatypePtr->size; size2 = obj2->obj_UnderlyingDatatypePtr->size;
switch (op) {
case Py_LT: c = size1 < size2; break;
case Py_LE: c = size1 <= size2; break;
case Py_EQ: c = size1 == size2; break;
case Py_NE: c = size1 != size2; break;
case Py_GT: c = size1 > size2; break;
case Py_GE: c... | trusted_official_docs | CPython Docs | size1 = obj1->obj_UnderlyingDatatypePtr->size; size2 = obj2->obj_UnderlyingDatatypePtr->size;
switch (op) {
case Py_LT: c = size1 < size2; break;
case Py_LE: c = size1 <= size2; break;
case Py_EQ: c = size1 == size2; break;
case Py_NE: c = size1 != size2; break;
case Py_GT: c = size1 > size2; break;
case Py_GE: c... | size1 = obj1->obj_UnderlyingDatatypePtr->size; size2 = obj2->obj_UnderlyingDatatypePtr->size;
switch (op) {
case Py_LT: c = size1 < size2; break;
case Py_LE: c = size1 <= size2; break;
case Py_EQ: c = size1 == size2; break;
case Py_NE: c = size1 != size2; break;
case Py_GT: c = size1 > size2; break;
case Py_GE: c... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b319bb1d-b438-4f1b-8459-3ce8c35c6240 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,216 | supabase-export-v2 | f4dfe15d81d881d3 | #. *self* is the instance of the data type which is the subject of the call. If the call is ``obj1('hello')``, then *self* is ``obj1``.
#. *args* is a tuple containing the arguments to the call. You can use
:c:func:`PyArg_ParseTuple` to extract the arguments. | trusted_official_docs | CPython Docs | #. *self* is the instance of the data type which is the subject of the call. If the call is ``obj1('hello')``, then *self* is ``obj1``.
#. *args* is a tuple containing the arguments to the call. You can use
:c:func:`PyArg_ParseTuple` to extract the arguments. | #. *self* is the instance of the data type which is the subject of the call. If the call is ``obj1('hello')``, then *self* is ``obj1``.
#. *args* is a tuple containing the arguments to the call. You can use
:c:func:`PyArg_ParseTuple` to extract the arguments. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b331acfb-1ed6-4f35-8c48-253b57e942bd | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,219 | supabase-export-v2 | ff1ec0457614d514 | Here is a toy ``tp_call`` implementation::
static PyObject *
newdatatype_call(PyObject *op, PyObject *args, PyObject *kwds)
{
newdatatypeobject *self = (newdatatypeobject *) op;
PyObject *result;
const char *arg1;
const char *arg2;
const char *arg3; | trusted_official_docs | CPython Docs | Here is a toy ``tp_call`` implementation::
static PyObject *
newdatatype_call(PyObject *op, PyObject *args, PyObject *kwds)
{
newdatatypeobject *self = (newdatatypeobject *) op;
PyObject *result;
const char *arg1;
const char *arg2;
const char *arg3; | Here is a toy ``tp_call`` implementation::
static PyObject *
newdatatype_call(PyObject *op, PyObject *args, PyObject *kwds)
{
newdatatypeobject *self = (newdatatypeobject *) op;
PyObject *result;
const char *arg1;
const char *arg2;
const char *arg3; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b5a65285-f698-4636-a0e7-e2c2a8cb5932 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,217 | supabase-export-v2 | 0b011a1863b73be1 | #. *args* is a tuple containing the arguments to the call. You can use :c:func:`PyArg_ParseTuple` to extract the arguments.
#. *kwds* is a dictionary of keyword arguments that were passed. If this is
non-``NULL`` and you support keyword arguments, use
:c:func:`PyArg_ParseTupleAndKeywords` to extract the arguments. If... | trusted_official_docs | CPython Docs | #. *args* is a tuple containing the arguments to the call. You can use :c:func:`PyArg_ParseTuple` to extract the arguments.
#. *kwds* is a dictionary of keyword arguments that were passed. If this is
non-``NULL`` and you support keyword arguments, use
:c:func:`PyArg_ParseTupleAndKeywords` to extract the arguments. If... | #. *args* is a tuple containing the arguments to the call. You can use :c:func:`PyArg_ParseTuple` to extract the arguments.
#. *kwds* is a dictionary of keyword arguments that were passed. If this is
non-``NULL`` and you support keyword arguments, use
:c:func:`PyArg_ParseTupleAndKeywords` to extract the arguments. If... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bacc0f43-39ae-4562-a5a0-810229f17043 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,164 | supabase-export-v2 | e5f104f84cf35bf8 | Attribute Management --------------------
For every object which can support attributes, the corresponding type must
provide the functions that control how the attributes are resolved. There needs
to be a function which can retrieve attributes (if any are defined), and another
to set attributes (if setting attributes i... | trusted_official_docs | CPython Docs | Attribute Management --------------------
For every object which can support attributes, the corresponding type must
provide the functions that control how the attributes are resolved. There needs
to be a function which can retrieve attributes (if any are defined), and another
to set attributes (if setting attributes i... | Attribute Management --------------------
For every object which can support attributes, the corresponding type must
provide the functions that control how the attributes are resolved. There needs
to be a function which can retrieve attributes (if any are defined), and another
to set attributes (if setting attributes i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c23ef9fd-d556-4414-85f1-629a01bb6701 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,234 | supabase-export-v2 | 1087169b5f294d24 | Concretely, here is how the statically declared type object would look::
static PyTypeObject TrivialType = {
PyVarObject_HEAD_INIT(NULL, 0)
/* ... other members omitted for brevity ... */
.tp_flags = Py_TPFLAGS_MANAGED_WEAKREF | ...,
}; | trusted_official_docs | CPython Docs | Concretely, here is how the statically declared type object would look::
static PyTypeObject TrivialType = {
PyVarObject_HEAD_INIT(NULL, 0)
/* ... other members omitted for brevity ... */
.tp_flags = Py_TPFLAGS_MANAGED_WEAKREF | ...,
}; | Concretely, here is how the statically declared type object would look::
static PyTypeObject TrivialType = {
PyVarObject_HEAD_INIT(NULL, 0)
/* ... other members omitted for brevity ... */
.tp_flags = Py_TPFLAGS_MANAGED_WEAKREF | ...,
}; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c4660592-6887-4823-9017-71f478cae000 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,143 | supabase-export-v2 | cbcc4ca8b1911cde | .. index:: single: PyErr_Fetch (C function) single: PyErr_Restore (C function)
One important requirement of the deallocator function is that it leaves any
pending exceptions alone. This is important since deallocators are frequently
called as the interpreter unwinds the Python stack; when the stack is unwound
due to an... | trusted_official_docs | CPython Docs | .. index:: single: PyErr_Fetch (C function) single: PyErr_Restore (C function)
One important requirement of the deallocator function is that it leaves any
pending exceptions alone. This is important since deallocators are frequently
called as the interpreter unwinds the Python stack; when the stack is unwound
due to an... | .. index:: single: PyErr_Fetch (C function) single: PyErr_Restore (C function)
One important requirement of the deallocator function is that it leaves any
pending exceptions alone. This is important since deallocators are frequently
called as the interpreter unwinds the Python stack; when the stack is unwound
due to an... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c5f54b46-b199-46e4-994f-9d18389d5dd2 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,177 | supabase-export-v2 | ad6c9b4e44fd255b | struct PyMethodDef *tp_methods; struct PyMemberDef *tp_members; struct PyGetSetDef *tp_getset;
If :c:member:`~PyTypeObject.tp_methods` is not ``NULL``, it must refer to an array of
:c:type:`PyMethodDef` structures. Each entry in the table is an instance of this
structure:: | trusted_official_docs | CPython Docs | struct PyMethodDef *tp_methods; struct PyMemberDef *tp_members; struct PyGetSetDef *tp_getset;
If :c:member:`~PyTypeObject.tp_methods` is not ``NULL``, it must refer to an array of
:c:type:`PyMethodDef` structures. Each entry in the table is an instance of this
structure:: | struct PyMethodDef *tp_methods; struct PyMemberDef *tp_members; struct PyGetSetDef *tp_getset;
If :c:member:`~PyTypeObject.tp_methods` is not ``NULL``, it must refer to an array of
:c:type:`PyMethodDef` structures. Each entry in the table is an instance of this
structure:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d25c6ba5-02a8-4ab9-94ab-77f73d27b203 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,236 | supabase-export-v2 | 065c60a9c40a5d19 | The only further addition is that ``tp_dealloc`` needs to clear any weak references (by calling :c:func:`PyObject_ClearWeakRefs`)::
static void
Trivial_dealloc(PyObject *op)
{
/* Clear weakrefs first before calling any destructors */
PyObject_ClearWeakRefs(op);
/* ... remainder of destruction code omitted for brev... | trusted_official_docs | CPython Docs | The only further addition is that ``tp_dealloc`` needs to clear any weak references (by calling :c:func:`PyObject_ClearWeakRefs`)::
static void
Trivial_dealloc(PyObject *op)
{
/* Clear weakrefs first before calling any destructors */
PyObject_ClearWeakRefs(op);
/* ... remainder of destruction code omitted for brev... | The only further addition is that ``tp_dealloc`` needs to clear any weak references (by calling :c:func:`PyObject_ClearWeakRefs`)::
static void
Trivial_dealloc(PyObject *op)
{
/* Clear weakrefs first before calling any destructors */
PyObject_ClearWeakRefs(op);
/* ... remainder of destruction code omitted for brev... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d32900c3-ec0a-4ec9-98e0-4997dc28d699 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,188 | supabase-export-v2 | e703b47b0252210c | Type-specific Attribute Management ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For simplicity, only the :c:expr:`char\*` version will be demonstrated here; the
type of the name parameter is the only difference between the :c:expr:`char\*`
and :c:expr:`PyObject*` flavors of the interface. This example effectively does
the same t... | trusted_official_docs | CPython Docs | Type-specific Attribute Management ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For simplicity, only the :c:expr:`char\*` version will be demonstrated here; the
type of the name parameter is the only difference between the :c:expr:`char\*`
and :c:expr:`PyObject*` flavors of the interface. This example effectively does
the same t... | Type-specific Attribute Management ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
For simplicity, only the :c:expr:`char\*` version will be demonstrated here; the
type of the name parameter is the only difference between the :c:expr:`char\*`
and :c:expr:`PyObject*` flavors of the interface. This example effectively does
the same t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d3868209-d9e8-45e9-94bb-e32583140b33 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,130 | supabase-export-v2 | f7d55ffe3c2c7d74 | chapter, this will appear in various places, almost entirely for diagnostic purposes. Try to choose something that will be helpful in such a situation! ::
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ | trusted_official_docs | CPython Docs | chapter, this will appear in various places, almost entirely for diagnostic purposes. Try to choose something that will be helpful in such a situation! ::
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ | chapter, this will appear in various places, almost entirely for diagnostic purposes. Try to choose something that will be helpful in such a situation! ::
Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d5d3ca2c-01be-4319-8c45-aeffaec50997 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,131 | supabase-export-v2 | 4748cfadbf01f08f | Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
These fields tell the runtime how much memory to allocate when new objects of
this type are created. Python has some built-in support for variable length
structures (think: strings, tuples) which is where the :c:member:`~PyTypeObject.tp_itemsize` field
comes in... | trusted_official_docs | CPython Docs | Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
These fields tell the runtime how much memory to allocate when new objects of
this type are created. Python has some built-in support for variable length
structures (think: strings, tuples) which is where the :c:member:`~PyTypeObject.tp_itemsize` field
comes in... | Py_ssize_t tp_basicsize, tp_itemsize; /* For allocation */
These fields tell the runtime how much memory to allocate when new objects of
this type are created. Python has some built-in support for variable length
structures (think: strings, tuples) which is where the :c:member:`~PyTypeObject.tp_itemsize` field
comes in... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d6b5e2a0-2597-4602-9505-5a6010e3047c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,213 | supabase-export-v2 | c5836f4954381f9d | ternaryfunc tp_call;
This function is called when an instance of your data type is "called", for
example, if ``obj1`` is an instance of your data type and the Python script
contains ``obj1('hello')``, the :c:member:`~PyTypeObject.tp_call` handler is invoked. | trusted_official_docs | CPython Docs | ternaryfunc tp_call;
This function is called when an instance of your data type is "called", for
example, if ``obj1`` is an instance of your data type and the Python script
contains ``obj1('hello')``, the :c:member:`~PyTypeObject.tp_call` handler is invoked. | ternaryfunc tp_call;
This function is called when an instance of your data type is "called", for
example, if ``obj1`` is an instance of your data type and the Python script
contains ``obj1('hello')``, the :c:member:`~PyTypeObject.tp_call` handler is invoked. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d80e26a7-a909-4dc4-bb5a-effbcd07e6b3 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,197 | supabase-export-v2 | de9a686721b7b8f1 | handler is called when comparisons are needed. It is analogous to the :ref:`rich comparison methods <richcmpfuncs>`, like :meth:`!__lt__`, and also called by :c:func:`PyObject_RichCompare` and :c:func:`PyObject_RichCompareBool`.
This function is called with two Python objects and the operator as arguments,
where the op... | trusted_official_docs | CPython Docs | handler is called when comparisons are needed. It is analogous to the :ref:`rich comparison methods <richcmpfuncs>`, like :meth:`!__lt__`, and also called by :c:func:`PyObject_RichCompare` and :c:func:`PyObject_RichCompareBool`.
This function is called with two Python objects and the operator as arguments,
where the op... | handler is called when comparisons are needed. It is analogous to the :ref:`rich comparison methods <richcmpfuncs>`, like :meth:`!__lt__`, and also called by :c:func:`PyObject_RichCompare` and :c:func:`PyObject_RichCompareBool`.
This function is called with two Python objects and the operator as arguments,
where the op... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dbfb6afc-14fa-4c10-9b96-0309c4a6f364 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,189 | supabase-export-v2 | 5d0244d83c021ec4 | It explains how the handler functions are called, so that if you do need to extend their functionality, you'll understand what needs to be done.
The :c:member:`~PyTypeObject.tp_getattr` handler is called when the object requires an attribute
look-up. It is called in the same situations where the :meth:`~object.__getatt... | trusted_official_docs | CPython Docs | It explains how the handler functions are called, so that if you do need to extend their functionality, you'll understand what needs to be done.
The :c:member:`~PyTypeObject.tp_getattr` handler is called when the object requires an attribute
look-up. It is called in the same situations where the :meth:`~object.__getatt... | It explains how the handler functions are called, so that if you do need to extend their functionality, you'll understand what needs to be done.
The :c:member:`~PyTypeObject.tp_getattr` handler is called when the object requires an attribute
look-up. It is called in the same situations where the :meth:`~object.__getatt... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dc0c640c-dc1a-4725-af4b-af920d9a33b4 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,171 | supabase-export-v2 | 933a63f37005cd9c | Most extension types only use *simple* attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:
#. The name of the attributes must be known when :c:func:`PyType_Ready` is
called. | trusted_official_docs | CPython Docs | Most extension types only use *simple* attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:
#. The name of the attributes must be known when :c:func:`PyType_Ready` is
called. | Most extension types only use *simple* attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:
#. The name of the attributes must be known when :c:func:`PyType_Ready` is
called. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e01208bc-313a-4bce-9f25-78dbe42dc9da | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,126 | supabase-export-v2 | 150ef2ac2c0339c8 | .. literalinclude:: ../includes/typestruct.h
Now that's a *lot* of methods. Don't worry too much though -- if you have
a type you want to define, the chances are very good that you will only
implement a handful of these. | trusted_official_docs | CPython Docs | .. literalinclude:: ../includes/typestruct.h
Now that's a *lot* of methods. Don't worry too much though -- if you have
a type you want to define, the chances are very good that you will only
implement a handful of these. | .. literalinclude:: ../includes/typestruct.h
Now that's a *lot* of methods. Don't worry too much though -- if you have
a type you want to define, the chances are very good that you will only
implement a handful of these. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e18a22ad-11b5-497a-ae8a-fcaca72e337f | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,239 | supabase-export-v2 | 7a0226fddd066263 | the C source files for ``tp_`` plus the function you want (for example, ``tp_richcompare``). You will find examples of the function you want to implement.
When you need to verify that an object is a concrete instance of the type you
are implementing, use the :c:func:`PyObject_TypeCheck` function. A sample of
its use mi... | trusted_official_docs | CPython Docs | the C source files for ``tp_`` plus the function you want (for example, ``tp_richcompare``). You will find examples of the function you want to implement.
When you need to verify that an object is a concrete instance of the type you
are implementing, use the :c:func:`PyObject_TypeCheck` function. A sample of
its use mi... | the C source files for ``tp_`` plus the function you want (for example, ``tp_richcompare``). You will find examples of the function you want to implement.
When you need to verify that an object is a concrete instance of the type you
are implementing, use the :c:func:`PyObject_TypeCheck` function. A sample of
its use mi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e3cafcda-3b77-4fa3-99d4-13649ecaa82e | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,140 | supabase-export-v2 | 92c06d87d6cdc712 | static void newdatatype_dealloc(PyObject *op) { newdatatypeobject *self = (newdatatypeobject *) op; free(self->obj_UnderlyingDatatypePtr); Py_TYPE(self)->tp_free(self); }
If your type supports garbage collection, the destructor should call
:c:func:`PyObject_GC_UnTrack` before clearing any member fields:: | trusted_official_docs | CPython Docs | static void newdatatype_dealloc(PyObject *op) { newdatatypeobject *self = (newdatatypeobject *) op; free(self->obj_UnderlyingDatatypePtr); Py_TYPE(self)->tp_free(self); }
If your type supports garbage collection, the destructor should call
:c:func:`PyObject_GC_UnTrack` before clearing any member fields:: | static void newdatatype_dealloc(PyObject *op) { newdatatypeobject *self = (newdatatypeobject *) op; free(self->obj_UnderlyingDatatypePtr); Py_TYPE(self)->tp_free(self); }
If your type supports garbage collection, the destructor should call
:c:func:`PyObject_GC_UnTrack` before clearing any member fields:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e70e9537-e242-44a7-a6c6-dd1d35398fa0 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,152 | supabase-export-v2 | e1fd48ceeb851c40 | Starting with Python 3.4, it is recommended not to put any complex finalization code in :c:member:`~PyTypeObject.tp_dealloc`, and instead use the new :c:member:`~PyTypeObject.tp_finalize` type method.
.. seealso::
:pep:`442` explains the new finalization scheme. | trusted_official_docs | CPython Docs | Starting with Python 3.4, it is recommended not to put any complex finalization code in :c:member:`~PyTypeObject.tp_dealloc`, and instead use the new :c:member:`~PyTypeObject.tp_finalize` type method.
.. seealso::
:pep:`442` explains the new finalization scheme. | Starting with Python 3.4, it is recommended not to put any complex finalization code in :c:member:`~PyTypeObject.tp_dealloc`, and instead use the new :c:member:`~PyTypeObject.tp_finalize` type method.
.. seealso::
:pep:`442` explains the new finalization scheme. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e7274a17-51e9-4272-a97d-6410ef2a63bf | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,178 | supabase-export-v2 | 49a661e3812db29d | If :c:member:`~PyTypeObject.tp_methods` is not ``NULL``, it must refer to an array of :c:type:`PyMethodDef` structures. Each entry in the table is an instance of this structure::
typedef struct PyMethodDef {
const char *ml_name; /* method name */
PyCFunction ml_meth; /* implementation function */
int ml_flags; /* fl... | trusted_official_docs | CPython Docs | If :c:member:`~PyTypeObject.tp_methods` is not ``NULL``, it must refer to an array of :c:type:`PyMethodDef` structures. Each entry in the table is an instance of this structure::
typedef struct PyMethodDef {
const char *ml_name; /* method name */
PyCFunction ml_meth; /* implementation function */
int ml_flags; /* fl... | If :c:member:`~PyTypeObject.tp_methods` is not ``NULL``, it must refer to an array of :c:type:`PyMethodDef` structures. Each entry in the table is an instance of this structure::
typedef struct PyMethodDef {
const char *ml_name; /* method name */
PyCFunction ml_meth; /* implementation function */
int ml_flags; /* fl... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e97eda65-ce24-4095-b530-9ea91a7715e7 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,211 | supabase-export-v2 | e4cb298059bff977 | = (newdatatypeobject *) op; Py_hash_t result; result = self->some_size + 32767 * self->some_number; if (result == -1) { result = -2; } return result; }
:c:type:`Py_hash_t` is a signed integer type with a platform-varying width. Returning ``-1`` from :c:member:`~PyTypeObject.tp_hash` indicates an error,
which is why you... | trusted_official_docs | CPython Docs | = (newdatatypeobject *) op; Py_hash_t result; result = self->some_size + 32767 * self->some_number; if (result == -1) { result = -2; } return result; }
:c:type:`Py_hash_t` is a signed integer type with a platform-varying width. Returning ``-1`` from :c:member:`~PyTypeObject.tp_hash` indicates an error,
which is why you... | = (newdatatypeobject *) op; Py_hash_t result; result = self->some_size + 32767 * self->some_number; if (result == -1) { result = -2; } return result; }
:c:type:`Py_hash_t` is a signed integer type with a platform-varying width. Returning ``-1`` from :c:member:`~PyTypeObject.tp_hash` indicates an error,
which is why you... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ebdd7dbb-b5b0-42a2-bba1-1d70ffe10e67 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,160 | supabase-export-v2 | 64a0a216469a0a9d | If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a representation that uses the type's :c:member:`~PyTypeObject.tp_name` and a uniquely identifying value for the object.
The :c:member:`~PyTypeObject.tp_str` handler is to :func:`str` what the :c:member:`~PyTypeObject.tp_repr` han... | trusted_official_docs | CPython Docs | If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a representation that uses the type's :c:member:`~PyTypeObject.tp_name` and a uniquely identifying value for the object.
The :c:member:`~PyTypeObject.tp_str` handler is to :func:`str` what the :c:member:`~PyTypeObject.tp_repr` han... | If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a representation that uses the type's :c:member:`~PyTypeObject.tp_name` and a uniquely identifying value for the object.
The :c:member:`~PyTypeObject.tp_str` handler is to :func:`str` what the :c:member:`~PyTypeObject.tp_repr` han... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ed8feda9-a90b-4d9b-a0c4-9a23ade4869a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,226 | supabase-export-v2 | 6aaa7d2677de139b | of iteration, such as file objects) can implement :c:member:`~PyTypeObject.tp_iter` by returning a new reference to themselves -- and should also therefore implement the :c:member:`~PyTypeObject.tp_iternext` handler.
Any :term:`iterator` object should implement both :c:member:`~PyTypeObject.tp_iter`
and :c:member:`~PyT... | trusted_official_docs | CPython Docs | of iteration, such as file objects) can implement :c:member:`~PyTypeObject.tp_iter` by returning a new reference to themselves -- and should also therefore implement the :c:member:`~PyTypeObject.tp_iternext` handler.
Any :term:`iterator` object should implement both :c:member:`~PyTypeObject.tp_iter`
and :c:member:`~PyT... | of iteration, such as file objects) can implement :c:member:`~PyTypeObject.tp_iter` by returning a new reference to themselves -- and should also therefore implement the :c:member:`~PyTypeObject.tp_iternext` handler.
Any :term:`iterator` object should implement both :c:member:`~PyTypeObject.tp_iter`
and :c:member:`~PyT... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
eee22782-1fb7-4146-9f64-8bed44cbfbfb | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,198 | supabase-export-v2 | b32ea9e3c820d6da | successful, ``Py_NotImplemented`` to indicate that comparison is not implemented and the other object's comparison method should be tried, or ``NULL`` if an exception was set.
Here is a sample implementation, for a datatype that is considered equal if the
size of an internal pointer is equal:: | trusted_official_docs | CPython Docs | successful, ``Py_NotImplemented`` to indicate that comparison is not implemented and the other object's comparison method should be tried, or ``NULL`` if an exception was set.
Here is a sample implementation, for a datatype that is considered equal if the
size of an internal pointer is equal:: | successful, ``Py_NotImplemented`` to indicate that comparison is not implemented and the other object's comparison method should be tried, or ``NULL`` if an exception was set.
Here is a sample implementation, for a datatype that is considered equal if the
size of an internal pointer is equal:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f1ecd0a7-3919-4e17-9f1e-ce1eaf230c39 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes.rst | unknown | 699ee406-54aa-4a51-b9e3-e55099910821 | 1,150 | supabase-export-v2 | 75e535177e34b751 | Py_DECREF(self->my_callback); } Py_TYPE(self)->tp_free(self); }
.. note::
There are limitations to what you can safely do in a deallocator function. First, if your type supports garbage collection (using :c:member:`~PyTypeObject.tp_traverse`
and/or :c:member:`~PyTypeObject.tp_clear`), some of the object's members can... | trusted_official_docs | CPython Docs | Py_DECREF(self->my_callback); } Py_TYPE(self)->tp_free(self); }
.. note::
There are limitations to what you can safely do in a deallocator function. First, if your type supports garbage collection (using :c:member:`~PyTypeObject.tp_traverse`
and/or :c:member:`~PyTypeObject.tp_clear`), some of the object's members can... | Py_DECREF(self->my_callback); } Py_TYPE(self)->tp_free(self); }
.. note::
There are limitations to what you can safely do in a deallocator function. First, if your type supports garbage collection (using :c:member:`~PyTypeObject.tp_traverse`
and/or :c:member:`~PyTypeObject.tp_clear`), some of the object's members can... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
03edbce2-bb84-4f52-b6f3-a2e0261dec80 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,402 | supabase-export-v2 | 2ce0334e7cecf416 | arg); if (vret != 0) return vret; } if (self->last) { vret = visit(self->last, arg); if (vret != 0) return vret; } return 0; }
For each subobject that can participate in cycles, we need to call the
:c:func:`!visit` function, which is passed to the traversal method. The
:c:func:`!visit` function takes as arguments the s... | trusted_official_docs | CPython Docs | arg); if (vret != 0) return vret; } if (self->last) { vret = visit(self->last, arg); if (vret != 0) return vret; } return 0; }
For each subobject that can participate in cycles, we need to call the
:c:func:`!visit` function, which is passed to the traversal method. The
:c:func:`!visit` function takes as arguments the s... | arg); if (vret != 0) return vret; } if (self->last) { vret = visit(self->last, arg); if (vret != 0) return vret; } return 0; }
For each subobject that can participate in cycles, we need to call the
:c:func:`!visit` function, which is passed to the traversal method. The
:c:func:`!visit` function takes as arguments the s... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0613bfab-9a42-4237-9288-9b4b72869487 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,412 | supabase-export-v2 | b04b72eaeefbbfc5 | Nevertheless, it is much easier and less error-prone to always use :c:func:`Py_CLEAR` when deleting an attribute. Don't try to micro-optimize at the expense of robustness!
The deallocator ``Custom_dealloc`` may call arbitrary code when clearing
attributes. It means the circular GC can be triggered inside the function. ... | trusted_official_docs | CPython Docs | Nevertheless, it is much easier and less error-prone to always use :c:func:`Py_CLEAR` when deleting an attribute. Don't try to micro-optimize at the expense of robustness!
The deallocator ``Custom_dealloc`` may call arbitrary code when clearing
attributes. It means the circular GC can be triggered inside the function. ... | Nevertheless, it is much easier and less error-prone to always use :c:func:`Py_CLEAR` when deleting an attribute. Don't try to micro-optimize at the expense of robustness!
The deallocator ``Custom_dealloc`` may call arbitrary code when clearing
attributes. It means the circular GC can be triggered inside the function. ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
08f47fe3-85dd-4428-819d-4bf539ea6c21 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,327 | supabase-export-v2 | 289b5b1554eec10c | Since memory allocation may fail, we must check the :c:member:`~PyTypeObject.tp_alloc` result against ``NULL`` before proceeding.
.. note::
We didn't fill the :c:member:`~PyTypeObject.tp_alloc` slot ourselves. Rather
:c:func:`PyType_Ready` fills it for us by inheriting it from our base class,
which is :class:`object... | trusted_official_docs | CPython Docs | Since memory allocation may fail, we must check the :c:member:`~PyTypeObject.tp_alloc` result against ``NULL`` before proceeding.
.. note::
We didn't fill the :c:member:`~PyTypeObject.tp_alloc` slot ourselves. Rather
:c:func:`PyType_Ready` fills it for us by inheriting it from our base class,
which is :class:`object... | Since memory allocation may fail, we must check the :c:member:`~PyTypeObject.tp_alloc` result against ``NULL`` before proceeding.
.. note::
We didn't fill the :c:member:`~PyTypeObject.tp_alloc` slot ourselves. Rather
:c:func:`PyType_Ready` fills it for us by inheriting it from our base class,
which is :class:`object... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0a5d4d77-b36a-452b-8110-c6917d842dff | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,360 | supabase-export-v2 | 178abff11469d157 | .tp_methods = Custom_methods,
Finally, we'll make our type usable as a base class for subclassing. We've
written our methods carefully so far so that they don't make any assumptions
about the type of the object being created or used, so all we need to do is
to add the :c:macro:`Py_TPFLAGS_BASETYPE` to our class flag de... | trusted_official_docs | CPython Docs | .tp_methods = Custom_methods,
Finally, we'll make our type usable as a base class for subclassing. We've
written our methods carefully so far so that they don't make any assumptions
about the type of the object being created or used, so all we need to do is
to add the :c:macro:`Py_TPFLAGS_BASETYPE` to our class flag de... | .tp_methods = Custom_methods,
Finally, we'll make our type usable as a base class for subclassing. We've
written our methods carefully so far so that they don't make any assumptions
about the type of the object being created or used, so all we need to do is
to add the :c:macro:`Py_TPFLAGS_BASETYPE` to our class flag de... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
0d7a0be3-e362-4e59-820f-461c3e4d8bd6 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,337 | supabase-export-v2 | 5f2349032de5f638 | we have to be extra careful when assigning the new attribute values. We might be tempted, for example to assign the ``first`` member like this::
if (first) {
Py_XDECREF(self->first);
Py_INCREF(first);
self->first = first;
} | trusted_official_docs | CPython Docs | we have to be extra careful when assigning the new attribute values. We might be tempted, for example to assign the ``first`` member like this::
if (first) {
Py_XDECREF(self->first);
Py_INCREF(first);
self->first = first;
} | we have to be extra careful when assigning the new attribute values. We might be tempted, for example to assign the ``first`` member like this::
if (first) {
Py_XDECREF(self->first);
Py_INCREF(first);
self->first = first;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1684bf1b-1726-477c-aee8-44a1558892cb | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,257 | supabase-export-v2 | fcb500d164629d06 | .. note:: There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be wary of adding one by accident: some compilers will complain.
Of course, objects generally store additional data besides the standard
``PyObject_HEAD`` boilerplate; for example, here is the definition for
standard Python floats:: | trusted_official_docs | CPython Docs | .. note:: There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be wary of adding one by accident: some compilers will complain.
Of course, objects generally store additional data besides the standard
``PyObject_HEAD`` boilerplate; for example, here is the definition for
standard Python floats:: | .. note:: There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be wary of adding one by accident: some compilers will complain.
Of course, objects generally store additional data besides the standard
``PyObject_HEAD`` boilerplate; for example, here is the definition for
standard Python floats:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
175696e3-0e1e-4b20-aefb-a1e7e4e50e7c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,426 | supabase-export-v2 | f2447e0e6b5de835 | that the base type's object structure must be the first value. The base type will already include the :c:func:`PyObject_HEAD` at the beginning of its structure.
When a Python object is a :class:`!SubList` instance, its ``PyObject *`` pointer
can be safely cast to both ``PyListObject *`` and ``SubListObject *``:: | trusted_official_docs | CPython Docs | that the base type's object structure must be the first value. The base type will already include the :c:func:`PyObject_HEAD` at the beginning of its structure.
When a Python object is a :class:`!SubList` instance, its ``PyObject *`` pointer
can be safely cast to both ``PyListObject *`` and ``SubListObject *``:: | that the base type's object structure must be the first value. The base type will already include the :c:func:`PyObject_HEAD` at the beginning of its structure.
When a Python object is a :class:`!SubList` instance, its ``PyObject *`` pointer
can be safely cast to both ``PyListObject *`` and ``SubListObject *``:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1b135935-5e2f-4439-8e82-5e728a94cac0 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,256 | supabase-export-v2 | 6695c1d6d6f45fc0 | macros :c:macro:`Py_TYPE` and :c:macro:`Py_REFCNT` respectively). The reason for the macro is to abstract away the layout and to enable additional fields in :ref:`debug builds <debug-build>`.
.. note::
There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be wary of adding one by accident: some compile... | trusted_official_docs | CPython Docs | macros :c:macro:`Py_TYPE` and :c:macro:`Py_REFCNT` respectively). The reason for the macro is to abstract away the layout and to enable additional fields in :ref:`debug builds <debug-build>`.
.. note::
There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be wary of adding one by accident: some compile... | macros :c:macro:`Py_TYPE` and :c:macro:`Py_REFCNT` respectively). The reason for the macro is to abstract away the layout and to enable additional fields in :ref:`debug builds <debug-build>`.
.. note::
There is no semicolon above after the :c:macro:`PyObject_HEAD` macro. Be wary of adding one by accident: some compile... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1bfca2fc-01e6-4273-a572-683ad66b0cc0 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,386 | supabase-export-v2 | cb10e4b520425a5b | PyObject *kwds) { CustomObject *self = (CustomObject *) op; static char *kwlist[] = {"first", "last", "number", NULL}; PyObject *first = NULL, *last = NULL, *tmp;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist,
&first, &last,
&self->number))
return -1; | trusted_official_docs | CPython Docs | PyObject *kwds) { CustomObject *self = (CustomObject *) op; static char *kwlist[] = {"first", "last", "number", NULL}; PyObject *first = NULL, *last = NULL, *tmp;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist,
&first, &last,
&self->number))
return -1; | PyObject *kwds) { CustomObject *self = (CustomObject *) op; static char *kwlist[] = {"first", "last", "number", NULL}; PyObject *first = NULL, *last = NULL, *tmp;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist,
&first, &last,
&self->number))
return -1; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
1c0f4a58-01ea-4c3e-b4ef-919d4c120c74 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,344 | supabase-export-v2 | e5adba29fbc6f628 | want to expose our instance variables as attributes. There are a number of ways to do that. The simplest way is to define member definitions::
static PyMemberDef Custom_members[] = {
{"first", Py_T_OBJECT_EX, offsetof(CustomObject, first), 0,
"first name"},
{"last", Py_T_OBJECT_EX, offsetof(CustomObject, last), 0,
... | trusted_official_docs | CPython Docs | want to expose our instance variables as attributes. There are a number of ways to do that. The simplest way is to define member definitions::
static PyMemberDef Custom_members[] = {
{"first", Py_T_OBJECT_EX, offsetof(CustomObject, first), 0,
"first name"},
{"last", Py_T_OBJECT_EX, offsetof(CustomObject, last), 0,
... | want to expose our instance variables as attributes. There are a number of ways to do that. The simplest way is to define member definitions::
static PyMemberDef Custom_members[] = {
{"first", Py_T_OBJECT_EX, offsetof(CustomObject, first), 0,
"first name"},
{"last", Py_T_OBJECT_EX, offsetof(CustomObject, last), 0,
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
202e8aef-38dc-4d3a-9731-392d85142430 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,284 | supabase-export-v2 | 804c0228e5fa2647 | if (PyType_Ready(&CustomType) < 0) { return -1; }
This initializes the :class:`!Custom` type, filling in a number of members
to the appropriate default values, including :c:member:`~PyObject.ob_type` that we initially
set to ``NULL``. :: | trusted_official_docs | CPython Docs | if (PyType_Ready(&CustomType) < 0) { return -1; }
This initializes the :class:`!Custom` type, filling in a number of members
to the appropriate default values, including :c:member:`~PyObject.ob_type` that we initially
set to ``NULL``. :: | if (PyType_Ready(&CustomType) < 0) { return -1; }
This initializes the :class:`!Custom` type, filling in a number of members
to the appropriate default values, including :c:member:`~PyObject.ob_type` that we initially
set to ``NULL``. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
22ee623e-fb77-453f-9b9d-0d19c04794a2 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,307 | supabase-export-v2 | abead9cad2048bc0 | typedef struct { PyObject_HEAD PyObject *first; /* first name */ PyObject *last; /* last name */ int number; } CustomObject;
Because we now have data to manage, we have to be more careful about object
allocation and deallocation. At a minimum, we need a deallocation method:: | trusted_official_docs | CPython Docs | typedef struct { PyObject_HEAD PyObject *first; /* first name */ PyObject *last; /* last name */ int number; } CustomObject;
Because we now have data to manage, we have to be more careful about object
allocation and deallocation. At a minimum, we need a deallocation method:: | typedef struct { PyObject_HEAD PyObject *first; /* first name */ PyObject *last; /* last name */ int number; } CustomObject;
Because we now have data to manage, we have to be more careful about object
allocation and deallocation. At a minimum, we need a deallocation method:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
23d6f701-e864-4aa6-808f-dbf7ced6f7d2 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,370 | supabase-export-v2 | 453d90c73d605fd3 | Providing finer control over data attributes ============================================
In this section, we'll provide finer control over how the :attr:`!first` and
:attr:`!last` attributes are set in the :class:`!Custom` example. In the previous
version of our module, the instance variables :attr:`!first` and :attr:... | trusted_official_docs | CPython Docs | Providing finer control over data attributes ============================================
In this section, we'll provide finer control over how the :attr:`!first` and
:attr:`!last` attributes are set in the :class:`!Custom` example. In the previous
version of our module, the instance variables :attr:`!first` and :attr:... | Providing finer control over data attributes ============================================
In this section, we'll provide finer control over how the :attr:`!first` and
:attr:`!last` attributes are set in the :class:`!Custom` example. In the previous
version of our module, the instance variables :attr:`!first` and :attr:... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
243d1e26-e5de-4e0d-a6e1-b7e5a8915ab5 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,246 | supabase-export-v2 | f478530e2074152c | The Basics ==========
The :term:`CPython` runtime sees all Python objects as variables of type
:c:expr:`PyObject*`, which serves as a "base type" for all Python objects. The :c:type:`PyObject` structure itself only contains the object's
:term:`reference count` and a pointer to the object's "type object". This is where ... | trusted_official_docs | CPython Docs | The Basics ==========
The :term:`CPython` runtime sees all Python objects as variables of type
:c:expr:`PyObject*`, which serves as a "base type" for all Python objects. The :c:type:`PyObject` structure itself only contains the object's
:term:`reference count` and a pointer to the object's "type object". This is where ... | The Basics ==========
The :term:`CPython` runtime sees all Python objects as variables of type
:c:expr:`PyObject*`, which serves as a "base type" for all Python objects. The :c:type:`PyObject` structure itself only contains the object's
:term:`reference count` and a pointer to the object's "type object". This is where ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
26d9aaa3-ace8-45f3-ad22-432e3ecb497e | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,272 | supabase-export-v2 | 63f493de24890b26 | .tp_basicsize = sizeof(CustomObject), .tp_itemsize = 0,
This is so that Python knows how much memory to allocate when creating
new :class:`!Custom` instances. :c:member:`~PyTypeObject.tp_itemsize` is
only used for variable-sized objects and should otherwise be zero. | trusted_official_docs | CPython Docs | .tp_basicsize = sizeof(CustomObject), .tp_itemsize = 0,
This is so that Python knows how much memory to allocate when creating
new :class:`!Custom` instances. :c:member:`~PyTypeObject.tp_itemsize` is
only used for variable-sized objects and should otherwise be zero. | .tp_basicsize = sizeof(CustomObject), .tp_itemsize = 0,
This is so that Python knows how much memory to allocate when creating
new :class:`!Custom` instances. :c:member:`~PyTypeObject.tp_itemsize` is
only used for variable-sized objects and should otherwise be zero. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
27408645-f010-4d80-a815-8b4396cbd25e | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,244 | supabase-export-v2 | ece2b516b4679da4 | ********************************** Defining Extension Types: Tutorial **********************************
Python allows the writer of a C extension module to define new types that
can be manipulated from Python code, much like the built-in :class:`str`
and :class:`list` types. The code for all extension types follows a
... | trusted_official_docs | CPython Docs | ********************************** Defining Extension Types: Tutorial **********************************
Python allows the writer of a C extension module to define new types that
can be manipulated from Python code, much like the built-in :class:`str`
and :class:`list` types. The code for all extension types follows a
... | ********************************** Defining Extension Types: Tutorial **********************************
Python allows the writer of a C extension module to define new types that
can be manipulated from Python code, much like the built-in :class:`str`
and :class:`list` types. The code for all extension types follows a
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
28927d20-1589-485b-8623-20fe257d0c1f | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,280 | supabase-export-v2 | bc27ace9471fd19d | .tp_doc = PyDoc_STR("Custom objects"),
To enable object creation, we have to provide a :c:member:`~PyTypeObject.tp_new`
handler. This is the equivalent of the Python method :meth:`~object.__new__`, but
has to be specified explicitly. In this case, we can just use the default
implementation provided by the API function ... | trusted_official_docs | CPython Docs | .tp_doc = PyDoc_STR("Custom objects"),
To enable object creation, we have to provide a :c:member:`~PyTypeObject.tp_new`
handler. This is the equivalent of the Python method :meth:`~object.__new__`, but
has to be specified explicitly. In this case, we can just use the default
implementation provided by the API function ... | .tp_doc = PyDoc_STR("Custom objects"),
To enable object creation, we have to provide a :c:member:`~PyTypeObject.tp_new`
handler. This is the equivalent of the Python method :meth:`~object.__new__`, but
has to be specified explicitly. In this case, we can just use the default
implementation provided by the API function ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2c5d0e57-34f4-4478-a0b5-fb05530b964a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,297 | supabase-export-v2 | 4c2a5799470a7af3 | $ python -m pip install .
in a shell should produce a file :file:`custom.so` in a subdirectory
and install it; now fire up Python --- you should be able to ``import custom``
and play around with ``Custom`` objects. | trusted_official_docs | CPython Docs | $ python -m pip install .
in a shell should produce a file :file:`custom.so` in a subdirectory
and install it; now fire up Python --- you should be able to ``import custom``
and play around with ``Custom`` objects. | $ python -m pip install .
in a shell should produce a file :file:`custom.so` in a subdirectory
and install it; now fire up Python --- you should be able to ``import custom``
and play around with ``Custom`` objects. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2d842271-f434-4d5a-b5de-2a5226e12735 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,374 | supabase-export-v2 | 55f6a1c730715893 | static PyObject * Custom_getfirst(PyObject *op, void *closure) { CustomObject *self = (CustomObject *) op; Py_INCREF(self->first); return self->first; }
static int
Custom_setfirst(PyObject *op, PyObject *value, void *closure)
{
CustomObject *self = (CustomObject *) op;
PyObject *tmp;
if (value == NULL) {
PyErr_Se... | trusted_official_docs | CPython Docs | static PyObject * Custom_getfirst(PyObject *op, void *closure) { CustomObject *self = (CustomObject *) op; Py_INCREF(self->first); return self->first; }
static int
Custom_setfirst(PyObject *op, PyObject *value, void *closure)
{
CustomObject *self = (CustomObject *) op;
PyObject *tmp;
if (value == NULL) {
PyErr_Se... | static PyObject * Custom_getfirst(PyObject *op, void *closure) { CustomObject *self = (CustomObject *) op; Py_INCREF(self->first); return self->first; }
static int
Custom_setfirst(PyObject *op, PyObject *value, void *closure)
{
CustomObject *self = (CustomObject *) op;
PyObject *tmp;
if (value == NULL) {
PyErr_Se... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
2f272594-ce02-451c-82d9-ef44c93ec1da | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,308 | supabase-export-v2 | 2a42d6ca34834bd1 | we now have data to manage, we have to be more careful about object allocation and deallocation. At a minimum, we need a deallocation method::
static void
Custom_dealloc(PyObject *op)
{
CustomObject *self = (CustomObject *) op;
Py_XDECREF(self->first);
Py_XDECREF(self->last);
Py_TYPE(self)->tp_free(self);
} | trusted_official_docs | CPython Docs | we now have data to manage, we have to be more careful about object allocation and deallocation. At a minimum, we need a deallocation method::
static void
Custom_dealloc(PyObject *op)
{
CustomObject *self = (CustomObject *) op;
Py_XDECREF(self->first);
Py_XDECREF(self->last);
Py_TYPE(self)->tp_free(self);
} | we now have data to manage, we have to be more careful about object allocation and deallocation. At a minimum, we need a deallocation method::
static void
Custom_dealloc(PyObject *op)
{
CustomObject *self = (CustomObject *) op;
Py_XDECREF(self->first);
Py_XDECREF(self->last);
Py_TYPE(self)->tp_free(self);
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3251d4e4-950c-4e4d-ae76-091be48ad9be | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,333 | supabase-export-v2 | 03f264aa88119d23 | { tmp = self->first; Py_INCREF(first); self->first = first; Py_XDECREF(tmp); } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_XDECREF(tmp); } return 0; }
by filling the :c:member:`~PyTypeObject.tp_init` slot. :: | trusted_official_docs | CPython Docs | { tmp = self->first; Py_INCREF(first); self->first = first; Py_XDECREF(tmp); } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_XDECREF(tmp); } return 0; }
by filling the :c:member:`~PyTypeObject.tp_init` slot. :: | { tmp = self->first; Py_INCREF(first); self->first = first; Py_XDECREF(tmp); } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_XDECREF(tmp); } return 0; }
by filling the :c:member:`~PyTypeObject.tp_init` slot. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
327ab6a3-e06f-46c3-843c-30b35f4e1316 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,398 | supabase-export-v2 | d711a884333fbbd5 | >>> import custom3 >>> class Derived(custom3.Custom): pass ... >>> n = Derived() >>> n.some_attribute = n
To allow a :class:`!Custom` instance participating in a reference cycle to
be properly detected and collected by the cyclic GC, our :class:`!Custom` type
needs to fill two additional slots and to enable a flag that... | trusted_official_docs | CPython Docs | >>> import custom3 >>> class Derived(custom3.Custom): pass ... >>> n = Derived() >>> n.some_attribute = n
To allow a :class:`!Custom` instance participating in a reference cycle to
be properly detected and collected by the cyclic GC, our :class:`!Custom` type
needs to fill two additional slots and to enable a flag that... | >>> import custom3 >>> class Derived(custom3.Custom): pass ... >>> n = Derived() >>> n.some_attribute = n
To allow a :class:`!Custom` instance participating in a reference cycle to
be properly detected and collected by the cyclic GC, our :class:`!Custom` type
needs to fill two additional slots and to enable a flag that... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
367883e0-e8fc-4cff-bc63-3fb11a644522 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,428 | supabase-export-v2 | 1de83f84f6ce53f2 | PyObject *args, PyObject *kwds) { SubListObject *self = (SubListObject *) op; if (PyList_Type.tp_init(op, args, kwds) < 0) return -1; self->state = 0; return 0; }
We see above how to call through to the :meth:`~object.__init__` method of the base
type. | trusted_official_docs | CPython Docs | PyObject *args, PyObject *kwds) { SubListObject *self = (SubListObject *) op; if (PyList_Type.tp_init(op, args, kwds) < 0) return -1; self->state = 0; return 0; }
We see above how to call through to the :meth:`~object.__init__` method of the base
type. | PyObject *args, PyObject *kwds) { SubListObject *self = (SubListObject *) op; if (PyList_Type.tp_init(op, args, kwds) < 0) return -1; self->state = 0; return 0; }
We see above how to call through to the :meth:`~object.__init__` method of the base
type. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
37770861-d483-4131-80bc-f1fb68ae5f79 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,274 | supabase-export-v2 | d076f2df865886aa | .. note::
If you want your type to be subclassable from Python, and your type has the same
:c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have problems with multiple
inheritance. A Python subclass of your type will have to list your type first
in its :attr:`~type.__bases__`, or else it will not be ... | trusted_official_docs | CPython Docs | .. note::
If you want your type to be subclassable from Python, and your type has the same
:c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have problems with multiple
inheritance. A Python subclass of your type will have to list your type first
in its :attr:`~type.__bases__`, or else it will not be ... | .. note::
If you want your type to be subclassable from Python, and your type has the same
:c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have problems with multiple
inheritance. A Python subclass of your type will have to list your type first
in its :attr:`~type.__bases__`, or else it will not be ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
377b86a7-5890-42ed-9847-dec13d2b71a5 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,439 | supabase-export-v2 | b0fa3b244cc4515e | .. [#] We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler in this example, because our type doesn't support garbage collection.
.. [#] We now know that the first and last members are strings, so perhaps we
could be less careful about decrementing their reference counts, however,
we accept instances... | trusted_official_docs | CPython Docs | .. [#] We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler in this example, because our type doesn't support garbage collection.
.. [#] We now know that the first and last members are strings, so perhaps we
could be less careful about decrementing their reference counts, however,
we accept instances... | .. [#] We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler in this example, because our type doesn't support garbage collection.
.. [#] We now know that the first and last members are strings, so perhaps we
could be less careful about decrementing their reference counts, however,
we accept instances... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3c51138b-3004-4980-8d7a-428bf0f90259 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,438 | supabase-export-v2 | 2d327385f6ac15e4 | .. [#] This is true when we know that the object is a basic type, like a string or a float.
.. [#] We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler
in this example, because our type doesn't support garbage collection. | trusted_official_docs | CPython Docs | .. [#] This is true when we know that the object is a basic type, like a string or a float.
.. [#] We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler
in this example, because our type doesn't support garbage collection. | .. [#] This is true when we know that the object is a basic type, like a string or a float.
.. [#] We relied on this in the :c:member:`~PyTypeObject.tp_dealloc` handler
in this example, because our type doesn't support garbage collection. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3d15227b-2c35-4571-b6b4-47f6751aead5 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,418 | supabase-export-v2 | cc96afb8b6e16441 | Subclassing other types =======================
It is possible to create new extension types that are derived from existing
types. It is easiest to inherit from the built in types, since an extension can
easily use the :c:type:`PyTypeObject` it needs. It can be difficult to share
these :c:type:`PyTypeObject` structures... | trusted_official_docs | CPython Docs | Subclassing other types =======================
It is possible to create new extension types that are derived from existing
types. It is easiest to inherit from the built in types, since an extension can
easily use the :c:type:`PyTypeObject` it needs. It can be difficult to share
these :c:type:`PyTypeObject` structures... | Subclassing other types =======================
It is possible to create new extension types that are derived from existing
types. It is easiest to inherit from the built in types, since an extension can
easily use the :c:type:`PyTypeObject` it needs. It can be difficult to share
these :c:type:`PyTypeObject` structures... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3daba4ae-dc6b-4fb2-bf35-e268a52c1adb | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,354 | supabase-export-v2 | cf2040c2495821d0 | def name(self): return "%s %s" % (self.first, self.last)
Note that we have to check for the possibility that our :attr:`!first` and
:attr:`!last` members are ``NULL``. This is because they can be deleted, in which
case they are set to ``NULL``. It would be better to prevent deletion of these
attributes and to restrict ... | trusted_official_docs | CPython Docs | def name(self): return "%s %s" % (self.first, self.last)
Note that we have to check for the possibility that our :attr:`!first` and
:attr:`!last` members are ``NULL``. This is because they can be deleted, in which
case they are set to ``NULL``. It would be better to prevent deletion of these
attributes and to restrict ... | def name(self): return "%s %s" % (self.first, self.last)
Note that we have to check for the possibility that our :attr:`!first` and
:attr:`!last` members are ``NULL``. This is because they can be deleted, in which
case they are set to ``NULL``. It would be better to prevent deletion of these
attributes and to restrict ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3ec90e86-240f-434c-8159-ee683d49bcca | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,252 | supabase-export-v2 | 6054d3c3304ad215 | Now that's quite a bit to take in at once, but hopefully bits will seem familiar from the previous chapter. This file defines three things:
#. What a :class:`!Custom` **object** contains: this is the ``CustomObject``
struct, which is allocated once for each :class:`!Custom` instance. #. How the :class:`!Custom` **type... | trusted_official_docs | CPython Docs | Now that's quite a bit to take in at once, but hopefully bits will seem familiar from the previous chapter. This file defines three things:
#. What a :class:`!Custom` **object** contains: this is the ``CustomObject``
struct, which is allocated once for each :class:`!Custom` instance. #. How the :class:`!Custom` **type... | Now that's quite a bit to take in at once, but hopefully bits will seem familiar from the previous chapter. This file defines three things:
#. What a :class:`!Custom` **object** contains: this is the ``CustomObject``
struct, which is allocated once for each :class:`!Custom` instance. #. How the :class:`!Custom` **type... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
3fbe8c5f-6fa9-4a7a-ae3c-4ca7bc6e99c9 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,258 | supabase-export-v2 | 0af588287786ffa6 | Of course, objects generally store additional data besides the standard ``PyObject_HEAD`` boilerplate; for example, here is the definition for standard Python floats::
typedef struct {
PyObject_HEAD
double ob_fval;
} PyFloatObject; | trusted_official_docs | CPython Docs | Of course, objects generally store additional data besides the standard ``PyObject_HEAD`` boilerplate; for example, here is the definition for standard Python floats::
typedef struct {
PyObject_HEAD
double ob_fval;
} PyFloatObject; | Of course, objects generally store additional data besides the standard ``PyObject_HEAD`` boilerplate; for example, here is the definition for standard Python floats::
typedef struct {
PyObject_HEAD
double ob_fval;
} PyFloatObject; | python, official-docs, cpython, P0 | Local_Trusted_Corpus |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.