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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
40299d0d-f1e1-41d3-bd59-85d329ee063e | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,263 | supabase-export-v2 | 4fa8bdf3a14c48e2 | The remaining fields will be filled with zeros by the C compiler, and it's common practice to not specify them explicitly unless you need them.
We're going to pick it apart, one field at a time:: | trusted_official_docs | CPython Docs | The remaining fields will be filled with zeros by the C compiler, and it's common practice to not specify them explicitly unless you need them.
We're going to pick it apart, one field at a time:: | The remaining fields will be filled with zeros by the C compiler, and it's common practice to not specify them explicitly unless you need them.
We're going to pick it apart, one field at a time:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
420ba087-616b-45a4-bc9c-21a4fec7cd32 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,355 | supabase-export-v2 | f8ca2daf607f7189 | to prevent deletion of these attributes and to restrict the attribute values to be strings. We'll see how to do that in the next section.
Now that we've defined the method, we need to create an array of method
definitions:: | trusted_official_docs | CPython Docs | to prevent deletion of these attributes and to restrict the attribute values to be strings. We'll see how to do that in the next section.
Now that we've defined the method, we need to create an array of method
definitions:: | to prevent deletion of these attributes and to restrict the attribute values to be strings. We'll see how to do that in the next section.
Now that we've defined the method, we need to create an array of method
definitions:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
426f92e5-4724-4486-8dca-9f71bcd3358c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,382 | supabase-export-v2 | 9a9931673be94a1d | The last item in a :c:type:`PyGetSetDef` structure is the "closure" mentioned above. In this case, we aren't using a closure, so we just pass ``NULL``.
We also remove the member definitions for these attributes:: | trusted_official_docs | CPython Docs | The last item in a :c:type:`PyGetSetDef` structure is the "closure" mentioned above. In this case, we aren't using a closure, so we just pass ``NULL``.
We also remove the member definitions for these attributes:: | The last item in a :c:type:`PyGetSetDef` structure is the "closure" mentioned above. In this case, we aren't using a closure, so we just pass ``NULL``.
We also remove the member definitions for these attributes:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
42f5e630-acdc-449c-ab93-990e4dac7bb0 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,260 | supabase-export-v2 | a3f165ee67259bc0 | The second bit is the definition of the type object. ::
static PyTypeObject CustomType = {
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom.Custom",
.tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericN... | trusted_official_docs | CPython Docs | The second bit is the definition of the type object. ::
static PyTypeObject CustomType = {
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom.Custom",
.tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericN... | The second bit is the definition of the type object. ::
static PyTypeObject CustomType = {
.ob_base = PyVarObject_HEAD_INIT(NULL, 0)
.tp_name = "custom.Custom",
.tp_doc = PyDoc_STR("Custom objects"),
.tp_basicsize = sizeof(CustomObject),
.tp_itemsize = 0,
.tp_flags = Py_TPFLAGS_DEFAULT,
.tp_new = PyType_GenericN... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
44dde9c4-261b-4ccd-b037-0e2e74cf507c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,343 | supabase-export-v2 | 917bf6e708beffa3 | * when decrementing a reference count in a :c:member:`~PyTypeObject.tp_dealloc` handler on a type which doesn't support cyclic garbage collection [#]_.
We 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:: | trusted_official_docs | CPython Docs | * when decrementing a reference count in a :c:member:`~PyTypeObject.tp_dealloc` handler on a type which doesn't support cyclic garbage collection [#]_.
We 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:: | * when decrementing a reference count in a :c:member:`~PyTypeObject.tp_dealloc` handler on a type which doesn't support cyclic garbage collection [#]_.
We 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:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
462d6e1b-c4f0-4855-b1fd-0a7a35db0207 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,315 | supabase-export-v2 | 87dea44cf759a6da | code, or in previous versions of this tutorial, you might see similar functions take a pointer to the subtype object structure (``CustomObject*``) directly, like this::
Custom_dealloc(CustomObject *self)
{
Py_XDECREF(self->first);
Py_XDECREF(self->last);
Py_TYPE(self)->tp_free((PyObject *) self);
}
... .tp_deallo... | trusted_official_docs | CPython Docs | code, or in previous versions of this tutorial, you might see similar functions take a pointer to the subtype object structure (``CustomObject*``) directly, like this::
Custom_dealloc(CustomObject *self)
{
Py_XDECREF(self->first);
Py_XDECREF(self->last);
Py_TYPE(self)->tp_free((PyObject *) self);
}
... .tp_deallo... | code, or in previous versions of this tutorial, you might see similar functions take a pointer to the subtype object structure (``CustomObject*``) directly, like this::
Custom_dealloc(CustomObject *self)
{
Py_XDECREF(self->first);
Py_XDECREF(self->last);
Py_TYPE(self)->tp_free((PyObject *) self);
}
... .tp_deallo... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4b4dabbd-566f-4d08-a6bc-928bf2116ff5 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,319 | supabase-export-v2 | 0b5aab3b04362e47 | Py_DECREF(self); return NULL; } self->last = PyUnicode_FromString(""); if (self->last == NULL) { Py_DECREF(self); return NULL; } self->number = 0; } return (PyObject *) self; }
and install it in the :c:member:`~PyTypeObject.tp_new` member:: | trusted_official_docs | CPython Docs | Py_DECREF(self); return NULL; } self->last = PyUnicode_FromString(""); if (self->last == NULL) { Py_DECREF(self); return NULL; } self->number = 0; } return (PyObject *) self; }
and install it in the :c:member:`~PyTypeObject.tp_new` member:: | Py_DECREF(self); return NULL; } self->last = PyUnicode_FromString(""); if (self->last == NULL) { Py_DECREF(self); return NULL; } self->number = 0; } return (PyObject *) self; }
and install it in the :c:member:`~PyTypeObject.tp_new` member:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4bfa9300-91d8-4275-99f7-e64b8e5ce8eb | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,338 | supabase-export-v2 | 125cb921334bb75c | if (first) { Py_XDECREF(self->first); Py_INCREF(first); self->first = first; }
But this would be risky. Our type doesn't restrict the type of the
``first`` member, so it could be any kind of object. It could have a
destructor that causes code to be executed that tries to access the
``first`` member; or that destructor ... | trusted_official_docs | CPython Docs | if (first) { Py_XDECREF(self->first); Py_INCREF(first); self->first = first; }
But this would be risky. Our type doesn't restrict the type of the
``first`` member, so it could be any kind of object. It could have a
destructor that causes code to be executed that tries to access the
``first`` member; or that destructor ... | if (first) { Py_XDECREF(self->first); Py_INCREF(first); self->first = first; }
But this would be risky. Our type doesn't restrict the type of the
``first`` member, so it could be any kind of object. It could have a
destructor that causes code to be executed that tries to access the
``first`` member; or that destructor ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4d141fd7-f87c-48eb-9498-f1c7a2b88478 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,405 | supabase-export-v2 | 59c26e4477111c9c | static int Custom_traverse(PyObject *op, visitproc visit, void *arg) { CustomObject *self = (CustomObject *) op; Py_VISIT(self->first); Py_VISIT(self->last); return 0; }
.. note::
The :c:member:`~PyTypeObject.tp_traverse` implementation must name its
arguments exactly *visit* and *arg* in order to use :c:func:`Py_VIS... | trusted_official_docs | CPython Docs | static int Custom_traverse(PyObject *op, visitproc visit, void *arg) { CustomObject *self = (CustomObject *) op; Py_VISIT(self->first); Py_VISIT(self->last); return 0; }
.. note::
The :c:member:`~PyTypeObject.tp_traverse` implementation must name its
arguments exactly *visit* and *arg* in order to use :c:func:`Py_VIS... | static int Custom_traverse(PyObject *op, visitproc visit, void *arg) { CustomObject *self = (CustomObject *) op; Py_VISIT(self->first); Py_VISIT(self->last); return 0; }
.. note::
The :c:member:`~PyTypeObject.tp_traverse` implementation must name its
arguments exactly *visit* and *arg* in order to use :c:func:`Py_VIS... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4fc944b0-326f-43f4-92af-0e7eea514002 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,373 | supabase-export-v2 | a36601c43666a5cf | control, over the :attr:`!first` and :attr:`!last` attributes, we'll use custom getter and setter functions. Here are the functions for getting and setting the :attr:`!first` attribute::
static PyObject *
Custom_getfirst(PyObject *op, void *closure)
{
CustomObject *self = (CustomObject *) op;
Py_INCREF(self->first)... | trusted_official_docs | CPython Docs | control, over the :attr:`!first` and :attr:`!last` attributes, we'll use custom getter and setter functions. Here are the functions for getting and setting the :attr:`!first` attribute::
static PyObject *
Custom_getfirst(PyObject *op, void *closure)
{
CustomObject *self = (CustomObject *) op;
Py_INCREF(self->first)... | control, over the :attr:`!first` and :attr:`!last` attributes, we'll use custom getter and setter functions. Here are the functions for getting and setting the :attr:`!first` attribute::
static PyObject *
Custom_getfirst(PyObject *op, void *closure)
{
CustomObject *self = (CustomObject *) op;
Py_INCREF(self->first)... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
519740a9-3be8-4651-9c22-9b15e4b4d699 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,351 | supabase-export-v2 | 2df924cc253d07b5 | (self->first == NULL) { PyErr_SetString(PyExc_AttributeError, "first"); return NULL; } if (self->last == NULL) { PyErr_SetString(PyExc_AttributeError, "last"); return NULL; } return PyUnicode_FromFormat("%S %S", self->first, self->last); }
The method is implemented as a C function that takes a :class:`!Custom` (or
:cla... | trusted_official_docs | CPython Docs | (self->first == NULL) { PyErr_SetString(PyExc_AttributeError, "first"); return NULL; } if (self->last == NULL) { PyErr_SetString(PyExc_AttributeError, "last"); return NULL; } return PyUnicode_FromFormat("%S %S", self->first, self->last); }
The method is implemented as a C function that takes a :class:`!Custom` (or
:cla... | (self->first == NULL) { PyErr_SetString(PyExc_AttributeError, "first"); return NULL; } if (self->last == NULL) { PyErr_SetString(PyExc_AttributeError, "last"); return NULL; } return PyUnicode_FromFormat("%S %S", self->first, self->last); }
The method is implemented as a C function that takes a :class:`!Custom` (or
:cla... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
523952bc-816a-4102-9d03-5cf276b13fa3 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,262 | supabase-export-v2 | 1f7969c8eb444177 | initializers as above, to avoid listing all the :c:type:`PyTypeObject` fields that you don't care about and also to avoid caring about the fields' declaration order.
The actual definition of :c:type:`PyTypeObject` in :file:`object.h` has
many more :ref:`fields <type-structs>` than the definition above. The
remaining fi... | trusted_official_docs | CPython Docs | initializers as above, to avoid listing all the :c:type:`PyTypeObject` fields that you don't care about and also to avoid caring about the fields' declaration order.
The actual definition of :c:type:`PyTypeObject` in :file:`object.h` has
many more :ref:`fields <type-structs>` than the definition above. The
remaining fi... | initializers as above, to avoid listing all the :c:type:`PyTypeObject` fields that you don't care about and also to avoid caring about the fields' declaration order.
The actual definition of :c:type:`PyTypeObject` in :file:`object.h` has
many more :ref:`fields <type-structs>` than the definition above. The
remaining fi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5246a8a4-3d44-49a1-87e6-9d1ffa813779 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,375 | supabase-export-v2 | eba157f919055342 | (!PyUnicode_Check(value)) { PyErr_SetString(PyExc_TypeError, "The first attribute value must be a string"); return -1; } tmp = self->first; Py_INCREF(value); self->first = value; Py_DECREF(tmp); return 0; }
The getter function is passed a :class:`!Custom` object and a "closure", which is
a void pointer. In this case, t... | trusted_official_docs | CPython Docs | (!PyUnicode_Check(value)) { PyErr_SetString(PyExc_TypeError, "The first attribute value must be a string"); return -1; } tmp = self->first; Py_INCREF(value); self->first = value; Py_DECREF(tmp); return 0; }
The getter function is passed a :class:`!Custom` object and a "closure", which is
a void pointer. In this case, t... | (!PyUnicode_Check(value)) { PyErr_SetString(PyExc_TypeError, "The first attribute value must be a string"); return -1; } tmp = self->first; Py_INCREF(value); self->first = value; Py_DECREF(tmp); return 0; }
The getter function is passed a :class:`!Custom` object and a "closure", which is
a void pointer. In this case, t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5dd13235-d089-438a-93cb-772f6ba759d5 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,304 | supabase-export-v2 | 9a4518cc2c1b6d68 | This version of the module has a number of changes.
The :class:`!Custom` type now has three data attributes in its C struct,
*first*, *last*, and *number*. The *first* and *last* variables are Python
strings containing first and last names. The *number* attribute is a C integer. | trusted_official_docs | CPython Docs | This version of the module has a number of changes.
The :class:`!Custom` type now has three data attributes in its C struct,
*first*, *last*, and *number*. The *first* and *last* variables are Python
strings containing first and last names. The *number* attribute is a C integer. | This version of the module has a number of changes.
The :class:`!Custom` type now has three data attributes in its C struct,
*first*, *last*, and *number*. The *first* and *last* variables are Python
strings containing first and last names. The *number* attribute is a C integer. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5ff39c51-9293-4744-a24b-272624a65f6f | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,385 | supabase-export-v2 | 85b3ffe4fa02c737 | We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only allow strings [#]_ to be passed::
static int
Custom_init(PyObject *op, PyObject *args, PyObject *kwds)
{
CustomObject *self = (CustomObject *) op;
static char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = ... | trusted_official_docs | CPython Docs | We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only allow strings [#]_ to be passed::
static int
Custom_init(PyObject *op, PyObject *args, PyObject *kwds)
{
CustomObject *self = (CustomObject *) op;
static char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = ... | We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only allow strings [#]_ to be passed::
static int
Custom_init(PyObject *op, PyObject *args, PyObject *kwds)
{
CustomObject *self = (CustomObject *) op;
static char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
66c4350a-7584-4779-891d-f1c3c6c27156 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,316 | supabase-export-v2 | 990ba733ddb4738f | Custom_dealloc(CustomObject *self) { Py_XDECREF(self->first); Py_XDECREF(self->last); Py_TYPE(self)->tp_free((PyObject *) self); } ... .tp_dealloc = (destructor) Custom_dealloc,
This does the same thing on all architectures that CPython
supports, but according to the C standard, it invokes
undefined behavior. | trusted_official_docs | CPython Docs | Custom_dealloc(CustomObject *self) { Py_XDECREF(self->first); Py_XDECREF(self->last); Py_TYPE(self)->tp_free((PyObject *) self); } ... .tp_dealloc = (destructor) Custom_dealloc,
This does the same thing on all architectures that CPython
supports, but according to the C standard, it invokes
undefined behavior. | Custom_dealloc(CustomObject *self) { Py_XDECREF(self->first); Py_XDECREF(self->last); Py_TYPE(self)->tp_free((PyObject *) self); } ... .tp_dealloc = (destructor) Custom_dealloc,
This does the same thing on all architectures that CPython
supports, but according to the C standard, it invokes
undefined behavior. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
685daa61-3e5b-40af-9d14-c7c92aa2be29 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,349 | supabase-export-v2 | 2e63ef1dbed51ff1 | Even though we can make sure the members are initialized to non-``NULL`` values, the members can be set to ``NULL`` if the attributes are deleted.
We define a single method, :meth:`!Custom.name`, that outputs the objects name as the
concatenation of the first and last names. :: | trusted_official_docs | CPython Docs | Even though we can make sure the members are initialized to non-``NULL`` values, the members can be set to ``NULL`` if the attributes are deleted.
We define a single method, :meth:`!Custom.name`, that outputs the objects name as the
concatenation of the first and last names. :: | Even though we can make sure the members are initialized to non-``NULL`` values, the members can be set to ``NULL`` if the attributes are deleted.
We define a single method, :meth:`!Custom.name`, that outputs the objects name as the
concatenation of the first and last names. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6c12288c-26d4-4b01-8841-f20840f6082c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,407 | supabase-export-v2 | 4ff10728bf77ad68 | Second, we need to provide a method for clearing any subobjects that can participate in cycles::
static int
Custom_clear(PyObject *op)
{
CustomObject *self = (CustomObject *) op;
Py_CLEAR(self->first);
Py_CLEAR(self->last);
return 0;
} | trusted_official_docs | CPython Docs | Second, we need to provide a method for clearing any subobjects that can participate in cycles::
static int
Custom_clear(PyObject *op)
{
CustomObject *self = (CustomObject *) op;
Py_CLEAR(self->first);
Py_CLEAR(self->last);
return 0;
} | Second, we need to provide a method for clearing any subobjects that can participate in cycles::
static int
Custom_clear(PyObject *op)
{
CustomObject *self = (CustomObject *) op;
Py_CLEAR(self->first);
Py_CLEAR(self->last);
return 0;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6c84c3f4-c240-4dc1-81b5-26994e6af20b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,408 | supabase-export-v2 | e520263df0b76da2 | static int Custom_clear(PyObject *op) { CustomObject *self = (CustomObject *) op; Py_CLEAR(self->first); Py_CLEAR(self->last); return 0; }
Notice the use of the :c:func:`Py_CLEAR` macro. It is the recommended and safe
way to clear data attributes of arbitrary types while decrementing
their reference counts. If you were... | trusted_official_docs | CPython Docs | static int Custom_clear(PyObject *op) { CustomObject *self = (CustomObject *) op; Py_CLEAR(self->first); Py_CLEAR(self->last); return 0; }
Notice the use of the :c:func:`Py_CLEAR` macro. It is the recommended and safe
way to clear data attributes of arbitrary types while decrementing
their reference counts. If you were... | static int Custom_clear(PyObject *op) { CustomObject *self = (CustomObject *) op; Py_CLEAR(self->first); Py_CLEAR(self->last); return 0; }
Notice the use of the :c:func:`Py_CLEAR` macro. It is the recommended and safe
way to clear data attributes of arbitrary types while decrementing
their reference counts. If you were... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6d6acb0c-1473-42d4-b473-74c08ac132e1 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,406 | supabase-export-v2 | cdd73194bd924b9a | .. note:: The :c:member:`~PyTypeObject.tp_traverse` implementation must name its arguments exactly *visit* and *arg* in order to use :c:func:`Py_VISIT`.
Second, we need to provide a method for clearing any subobjects that can
participate in cycles:: | trusted_official_docs | CPython Docs | .. note:: The :c:member:`~PyTypeObject.tp_traverse` implementation must name its arguments exactly *visit* and *arg* in order to use :c:func:`Py_VISIT`.
Second, we need to provide a method for clearing any subobjects that can
participate in cycles:: | .. note:: The :c:member:`~PyTypeObject.tp_traverse` implementation must name its arguments exactly *visit* and *arg* in order to use :c:func:`Py_VISIT`.
Second, we need to provide a method for clearing any subobjects that can
participate in cycles:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
6e2f17cb-4bee-449a-8903-75cb40f2b166 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,390 | supabase-export-v2 | 7ffb05eb50c34b4a | the module initialization function and module name in the initialization function, as we did before, and we add an extra definition to the :file:`setup.py` file.
Supporting cyclic garbage collection
==================================== | trusted_official_docs | CPython Docs | the module initialization function and module name in the initialization function, as we did before, and we add an extra definition to the :file:`setup.py` file.
Supporting cyclic garbage collection
==================================== | the module initialization function and module name in the initialization function, as we did before, and we add an extra definition to the :file:`setup.py` file.
Supporting cyclic garbage collection
==================================== | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
70d763b6-323b-4a1d-9aa3-389d793a41be | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,403 | supabase-export-v2 | a72bfa21732b6600 | the subobject and the extra argument *arg* passed to the traversal method. It returns an integer value that must be returned if it is non-zero.
Python provides a :c:func:`Py_VISIT` macro that automates calling visit
functions. With :c:func:`Py_VISIT`, we can minimize the amount of boilerplate
in ``Custom_traverse``:: | trusted_official_docs | CPython Docs | the subobject and the extra argument *arg* passed to the traversal method. It returns an integer value that must be returned if it is non-zero.
Python provides a :c:func:`Py_VISIT` macro that automates calling visit
functions. With :c:func:`Py_VISIT`, we can minimize the amount of boilerplate
in ``Custom_traverse``:: | the subobject and the extra argument *arg* passed to the traversal method. It returns an integer value that must be returned if it is non-zero.
Python provides a :c:func:`Py_VISIT` macro that automates calling visit
functions. With :c:func:`Py_VISIT`, we can minimize the amount of boilerplate
in ``Custom_traverse``:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
728a1241-d459-441e-8067-8fae61a320cb | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,376 | supabase-export-v2 | aa01863b5a2b29e6 | used to allow a single set of getter and setter functions that decide the attribute to get or set based on data in the closure.)
The setter function is passed the :class:`!Custom` object, the new value, and the
closure. The new value may be ``NULL``, in which case the attribute is being
deleted. In our setter, we raise... | trusted_official_docs | CPython Docs | used to allow a single set of getter and setter functions that decide the attribute to get or set based on data in the closure.)
The setter function is passed the :class:`!Custom` object, the new value, and the
closure. The new value may be ``NULL``, in which case the attribute is being
deleted. In our setter, we raise... | used to allow a single set of getter and setter functions that decide the attribute to get or set based on data in the closure.)
The setter function is passed the :class:`!Custom` object, the new value, and the
closure. The new value may be ``NULL``, in which case the attribute is being
deleted. In our setter, we raise... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
732ee0a9-81b0-4593-86fb-99cba2bb6cd9 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,270 | supabase-export-v2 | d7bdc66dfab77459 | >>> "" + custom.Custom() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate str (not "custom.Custom") to str
Note that the name is a dotted name that includes both the module name and the
name of the type within the module. The module in this case is :mod:`!custom` an... | trusted_official_docs | CPython Docs | >>> "" + custom.Custom() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate str (not "custom.Custom") to str
Note that the name is a dotted name that includes both the module name and the
name of the type within the module. The module in this case is :mod:`!custom` an... | >>> "" + custom.Custom() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: can only concatenate str (not "custom.Custom") to str
Note that the name is a dotted name that includes both the module name and the
name of the type within the module. The module in this case is :mod:`!custom` an... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
78a73f7e-be96-4c4b-862b-417c72fa83c7 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,356 | supabase-export-v2 | b88ab436dea5798a | Now that we've defined the method, we need to create an array of method definitions::
static PyMethodDef Custom_methods[] = {
{"name", Custom_name, METH_NOARGS,
"Return the name, combining the first and last name"
},
{NULL} /* Sentinel */
}; | trusted_official_docs | CPython Docs | Now that we've defined the method, we need to create an array of method definitions::
static PyMethodDef Custom_methods[] = {
{"name", Custom_name, METH_NOARGS,
"Return the name, combining the first and last name"
},
{NULL} /* Sentinel */
}; | Now that we've defined the method, we need to create an array of method definitions::
static PyMethodDef Custom_methods[] = {
{"name", Custom_name, METH_NOARGS,
"Return the name, combining the first and last name"
},
{NULL} /* Sentinel */
}; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
79a42c30-a96c-4442-886d-1ca04f4e4600 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,318 | supabase-export-v2 | 6ad397c548b51a81 | We want to make sure that the first and last names are initialized to empty strings, so we provide a ``tp_new`` implementation::
static PyObject *
Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
CustomObject *self;
self = (CustomObject *) type->tp_alloc(type, 0);
if (self != NULL) {
self->first =... | trusted_official_docs | CPython Docs | We want to make sure that the first and last names are initialized to empty strings, so we provide a ``tp_new`` implementation::
static PyObject *
Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
CustomObject *self;
self = (CustomObject *) type->tp_alloc(type, 0);
if (self != NULL) {
self->first =... | We want to make sure that the first and last names are initialized to empty strings, so we provide a ``tp_new`` implementation::
static PyObject *
Custom_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
CustomObject *self;
self = (CustomObject *) type->tp_alloc(type, 0);
if (self != NULL) {
self->first =... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7a84afd2-8b37-426f-bb04-f6c976cbec0f | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,429 | supabase-export-v2 | edafdefcae95d427 | We see above how to call through to the :meth:`~object.__init__` method of the base type.
This pattern is important when writing a type with custom
:c:member:`~PyTypeObject.tp_new` and :c:member:`~PyTypeObject.tp_dealloc`
members. The :c:member:`~PyTypeObject.tp_new` handler should not actually
create the memory for th... | trusted_official_docs | CPython Docs | We see above how to call through to the :meth:`~object.__init__` method of the base type.
This pattern is important when writing a type with custom
:c:member:`~PyTypeObject.tp_new` and :c:member:`~PyTypeObject.tp_dealloc`
members. The :c:member:`~PyTypeObject.tp_new` handler should not actually
create the memory for th... | We see above how to call through to the :meth:`~object.__init__` method of the base type.
This pattern is important when writing a type with custom
:c:member:`~PyTypeObject.tp_new` and :c:member:`~PyTypeObject.tp_dealloc`
members. The :c:member:`~PyTypeObject.tp_new` handler should not actually
create the memory for th... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7a8af6e0-5f74-4234-8945-2784056fc7b7 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,401 | supabase-export-v2 | 59470db21f027b49 | First, the traversal method lets the cyclic GC know about subobjects that could participate in cycles::
static int
Custom_traverse(PyObject *op, visitproc visit, void *arg)
{
CustomObject *self = (CustomObject *) op;
int vret;
if (self->first) {
vret = visit(self->first, arg);
if (vret != 0)
return vret;
}
if... | trusted_official_docs | CPython Docs | First, the traversal method lets the cyclic GC know about subobjects that could participate in cycles::
static int
Custom_traverse(PyObject *op, visitproc visit, void *arg)
{
CustomObject *self = (CustomObject *) op;
int vret;
if (self->first) {
vret = visit(self->first, arg);
if (vret != 0)
return vret;
}
if... | First, the traversal method lets the cyclic GC know about subobjects that could participate in cycles::
static int
Custom_traverse(PyObject *op, visitproc visit, void *arg)
{
CustomObject *self = (CustomObject *) op;
int vret;
if (self->first) {
vret = visit(self->first, arg);
if (vret != 0)
return vret;
}
if... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7d9ab3f5-47b8-4dea-8895-41286349c495 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,271 | supabase-export-v2 | 5467c5ef15c22236 | the type name to :class:`!custom.Custom`. Using the real dotted import path is important to make your type compatible with the :mod:`pydoc` and :mod:`pickle` modules. ::
.tp_basicsize = sizeof(CustomObject),
.tp_itemsize = 0, | trusted_official_docs | CPython Docs | the type name to :class:`!custom.Custom`. Using the real dotted import path is important to make your type compatible with the :mod:`pydoc` and :mod:`pickle` modules. ::
.tp_basicsize = sizeof(CustomObject),
.tp_itemsize = 0, | the type name to :class:`!custom.Custom`. Using the real dotted import path is important to make your type compatible with the :mod:`pydoc` and :mod:`pickle` modules. ::
.tp_basicsize = sizeof(CustomObject),
.tp_itemsize = 0, | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7e056415-18a5-4c1c-973b-193250b00510 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,339 | supabase-export-v2 | 0041c06ceed07441 | or that destructor could detach the :term:`thread state <attached thread state>` and let arbitrary code run in other threads that accesses and modifies our object.
To be paranoid and protect ourselves against this possibility, we almost
always reassign members before decrementing their reference counts. When
don't we h... | trusted_official_docs | CPython Docs | or that destructor could detach the :term:`thread state <attached thread state>` and let arbitrary code run in other threads that accesses and modifies our object.
To be paranoid and protect ourselves against this possibility, we almost
always reassign members before decrementing their reference counts. When
don't we h... | or that destructor could detach the :term:`thread state <attached thread state>` and let arbitrary code run in other threads that accesses and modifies our object.
To be paranoid and protect ourselves against this possibility, we almost
always reassign members before decrementing their reference counts. When
don't we h... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
7e249f3c-70b7-4f93-a007-9d9a5265ca29 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,395 | supabase-export-v2 | 9e01da4d121d3b3f | itself. Its reference count doesn't drop to zero. Fortunately, Python's cyclic garbage collector will eventually figure out that the list is garbage and free it.
In the second version of the :class:`!Custom` example, we allowed any kind of
object to be stored in the :attr:`!first` or :attr:`!last` attributes [#]_. Besi... | trusted_official_docs | CPython Docs | itself. Its reference count doesn't drop to zero. Fortunately, Python's cyclic garbage collector will eventually figure out that the list is garbage and free it.
In the second version of the :class:`!Custom` example, we allowed any kind of
object to be stored in the :attr:`!first` or :attr:`!last` attributes [#]_. Besi... | itself. Its reference count doesn't drop to zero. Fortunately, Python's cyclic garbage collector will eventually figure out that the list is garbage and free it.
In the second version of the :class:`!Custom` example, we allowed any kind of
object to be stored in the :attr:`!first` or :attr:`!last` attributes [#]_. Besi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8048cbbb-fd6e-41ef-9a65-9b6ee0bf5f3a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,300 | supabase-export-v2 | 06cf4c4fb665a0f4 | Of course, the current Custom type is pretty uninteresting. It has no data and doesn't do anything. It can't even be subclassed.
Adding data and methods to the Basic example
============================================ | trusted_official_docs | CPython Docs | Of course, the current Custom type is pretty uninteresting. It has no data and doesn't do anything. It can't even be subclassed.
Adding data and methods to the Basic example
============================================ | Of course, the current Custom type is pretty uninteresting. It has no data and doesn't do anything. It can't even be subclassed.
Adding data and methods to the Basic example
============================================ | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
83543644-b70f-487e-9232-0921984fc23f | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,391 | supabase-export-v2 | 31eccfb1f3efea91 | Supporting cyclic garbage collection ====================================
Python has a :term:`cyclic garbage collector (GC) <garbage collection>` that
can identify unneeded objects even when their reference counts are not zero. This can happen when objects are involved in cycles. For example, consider: | trusted_official_docs | CPython Docs | Supporting cyclic garbage collection ====================================
Python has a :term:`cyclic garbage collector (GC) <garbage collection>` that
can identify unneeded objects even when their reference counts are not zero. This can happen when objects are involved in cycles. For example, consider: | Supporting cyclic garbage collection ====================================
Python has a :term:`cyclic garbage collector (GC) <garbage collection>` that
can identify unneeded objects even when their reference counts are not zero. This can happen when objects are involved in cycles. For example, consider: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
849e94f3-694e-49d5-8622-55e2e374a2b5 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,388 | supabase-export-v2 | 623c4025ba83ee90 | { tmp = self->first; Py_INCREF(first); self->first = first; Py_DECREF(tmp); } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_DECREF(tmp); } return 0; }
With these changes, we can assure that the ``first`` and ``last`` members are
never ``NULL`` so we can remove checks for ``NULL`` values in almost... | trusted_official_docs | CPython Docs | { tmp = self->first; Py_INCREF(first); self->first = first; Py_DECREF(tmp); } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_DECREF(tmp); } return 0; }
With these changes, we can assure that the ``first`` and ``last`` members are
never ``NULL`` so we can remove checks for ``NULL`` values in almost... | { tmp = self->first; Py_INCREF(first); self->first = first; Py_DECREF(tmp); } if (last) { tmp = self->last; Py_INCREF(last); self->last = last; Py_DECREF(tmp); } return 0; }
With these changes, we can assure that the ``first`` and ``last`` members are
never ``NULL`` so we can remove checks for ``NULL`` values in almost... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
84aa8d0f-2d52-47e9-9dd2-9fbb0571c5d8 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,298 | supabase-export-v2 | 7b9bbbf5c0469b24 | :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.
That wasn't so hard, was it? | trusted_official_docs | CPython Docs | :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.
That wasn't so hard, was it? | :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.
That wasn't so hard, was it? | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
84fe843a-6888-4057-9b04-db5afca7f8bc | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,277 | supabase-export-v2 | 118af64fc9417eee | .tp_flags = Py_TPFLAGS_DEFAULT,
All types should include this constant in their flags. It enables all of the
members defined until at least Python 3.3. If you need further members,
you will need to OR the corresponding flags. | trusted_official_docs | CPython Docs | .tp_flags = Py_TPFLAGS_DEFAULT,
All types should include this constant in their flags. It enables all of the
members defined until at least Python 3.3. If you need further members,
you will need to OR the corresponding flags. | .tp_flags = Py_TPFLAGS_DEFAULT,
All types should include this constant in their flags. It enables all of the
members defined until at least Python 3.3. If you need further members,
you will need to OR the corresponding flags. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
855dcdb2-b826-4af4-b4bd-e1538f914ed7 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,340 | supabase-export-v2 | 169d54d9453ce57d | be paranoid and protect ourselves against this possibility, we almost always reassign members before decrementing their reference counts. When don't we have to do this?
* when we absolutely know that the reference count is greater than 1; | trusted_official_docs | CPython Docs | be paranoid and protect ourselves against this possibility, we almost always reassign members before decrementing their reference counts. When don't we have to do this?
* when we absolutely know that the reference count is greater than 1; | be paranoid and protect ourselves against this possibility, we almost always reassign members before decrementing their reference counts. When don't we have to do this?
* when we absolutely know that the reference count is greater than 1; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
88b04c01-cf77-4054-9a2b-ddca3e781ee6 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,249 | supabase-export-v2 | 3f3d1cb93b6ba613 | only be explained by example, so here's a minimal, but complete, module that defines a new type named :class:`!Custom` inside a C extension module :mod:`!custom`:
.. note::
What we're showing here is the traditional way of defining *static*
extension types. It should be adequate for most uses. The C API also
allows ... | trusted_official_docs | CPython Docs | only be explained by example, so here's a minimal, but complete, module that defines a new type named :class:`!Custom` inside a C extension module :mod:`!custom`:
.. note::
What we're showing here is the traditional way of defining *static*
extension types. It should be adequate for most uses. The C API also
allows ... | only be explained by example, so here's a minimal, but complete, module that defines a new type named :class:`!Custom` inside a C extension module :mod:`!custom`:
.. note::
What we're showing here is the traditional way of defining *static*
extension types. It should be adequate for most uses. The C API also
allows ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8a5a882d-a275-4cbf-b15d-c39b1e6cba59 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,275 | supabase-export-v2 | 6dff354b3937bdae | because either your base type will be :class:`object`, or else you will be adding data members to your base type, and therefore increasing its size.
We set the class flags to :c:macro:`Py_TPFLAGS_DEFAULT`. :: | trusted_official_docs | CPython Docs | because either your base type will be :class:`object`, or else you will be adding data members to your base type, and therefore increasing its size.
We set the class flags to :c:macro:`Py_TPFLAGS_DEFAULT`. :: | because either your base type will be :class:`object`, or else you will be adding data members to your base type, and therefore increasing its size.
We set the class flags to :c:macro:`Py_TPFLAGS_DEFAULT`. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
8d359800-79c0-40ed-b1ef-7b7d53c7bc35 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,427 | supabase-export-v2 | 22177a8021b1df82 | When a Python object is a :class:`!SubList` instance, its ``PyObject *`` pointer can be safely cast to both ``PyListObject *`` and ``SubListObject *``::
static int
SubList_init(PyObject *op, PyObject *args, PyObject *kwds)
{
SubListObject *self = (SubListObject *) op;
if (PyList_Type.tp_init(op, args, kwds) < 0)
r... | trusted_official_docs | CPython Docs | When a Python object is a :class:`!SubList` instance, its ``PyObject *`` pointer can be safely cast to both ``PyListObject *`` and ``SubListObject *``::
static int
SubList_init(PyObject *op, PyObject *args, PyObject *kwds)
{
SubListObject *self = (SubListObject *) op;
if (PyList_Type.tp_init(op, args, kwds) < 0)
r... | When a Python object is a :class:`!SubList` instance, its ``PyObject *`` pointer can be safely cast to both ``PyListObject *`` and ``SubListObject *``::
static int
SubList_init(PyObject *op, PyObject *args, PyObject *kwds)
{
SubListObject *self = (SubListObject *) op;
if (PyList_Type.tp_init(op, args, kwds) < 0)
r... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9329bd9a-6d3f-4a1d-8def-0c63ed160cab | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,372 | supabase-export-v2 | 2f87b292bca41887 | .. literalinclude:: ../includes/newtypes/custom3.c
To provide greater control, over the :attr:`!first` and :attr:`!last` attributes,
we'll use custom getter and setter functions. Here are the functions for
getting and setting the :attr:`!first` attribute:: | trusted_official_docs | CPython Docs | .. literalinclude:: ../includes/newtypes/custom3.c
To provide greater control, over the :attr:`!first` and :attr:`!last` attributes,
we'll use custom getter and setter functions. Here are the functions for
getting and setting the :attr:`!first` attribute:: | .. literalinclude:: ../includes/newtypes/custom3.c
To provide greater control, over the :attr:`!first` and :attr:`!last` attributes,
we'll use custom getter and setter functions. Here are the functions for
getting and setting the :attr:`!first` attribute:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
93d7439e-1db9-4c23-a500-f9811d49d07b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,336 | supabase-export-v2 | c48f5b4e680b0bc0 | initialize an object after it's created. Initializers always accept positional and keyword arguments, and they should return either ``0`` on success or ``-1`` on error.
Unlike the ``tp_new`` handler, there is no guarantee that ``tp_init``
is called at all (for example, the :mod:`pickle` module by default
doesn't call :... | trusted_official_docs | CPython Docs | initialize an object after it's created. Initializers always accept positional and keyword arguments, and they should return either ``0`` on success or ``-1`` on error.
Unlike the ``tp_new`` handler, there is no guarantee that ``tp_init``
is called at all (for example, the :mod:`pickle` module by default
doesn't call :... | initialize an object after it's created. Initializers always accept positional and keyword arguments, and they should return either ``0`` on success or ``-1`` on error.
Unlike the ``tp_new`` handler, there is no guarantee that ``tp_init``
is called at all (for example, the :mod:`pickle` module by default
doesn't call :... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
96beec48-445c-46b7-a1dd-d5eb36148822 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,278 | supabase-export-v2 | a8419d912b763498 | It enables all of the members defined until at least Python 3.3. If you need further members, you will need to OR the corresponding flags.
We provide a doc string for the type in :c:member:`~PyTypeObject.tp_doc`. :: | trusted_official_docs | CPython Docs | It enables all of the members defined until at least Python 3.3. If you need further members, you will need to OR the corresponding flags.
We provide a doc string for the type in :c:member:`~PyTypeObject.tp_doc`. :: | It enables all of the members defined until at least Python 3.3. If you need further members, you will need to OR the corresponding flags.
We provide a doc string for the type in :c:member:`~PyTypeObject.tp_doc`. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
996c1b6a-9c38-4563-9a34-deed9ef6f6b7 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,311 | supabase-export-v2 | 5c25df5410c6ec6a | .tp_dealloc = Custom_dealloc,
This method first clears the reference counts of the two Python attributes. :c:func:`Py_XDECREF` correctly handles the case where its argument is
``NULL`` (which might happen here if ``tp_new`` failed midway). It then
calls the :c:member:`~PyTypeObject.tp_free` member of the object's type
... | trusted_official_docs | CPython Docs | .tp_dealloc = Custom_dealloc,
This method first clears the reference counts of the two Python attributes. :c:func:`Py_XDECREF` correctly handles the case where its argument is
``NULL`` (which might happen here if ``tp_new`` failed midway). It then
calls the :c:member:`~PyTypeObject.tp_free` member of the object's type
... | .tp_dealloc = Custom_dealloc,
This method first clears the reference counts of the two Python attributes. :c:func:`Py_XDECREF` correctly handles the case where its argument is
``NULL`` (which might happen here if ``tp_new`` failed midway). It then
calls the :c:member:`~PyTypeObject.tp_free` member of the object's type
... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
9aa4a5e7-87da-41c1-a515-8906479ee214 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,285 | supabase-export-v2 | d782a2133b05745e | 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 (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
return -1;
} | trusted_official_docs | CPython Docs | 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 (PyModule_AddObjectRef(m, "Custom", (PyObject *) &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 (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {
return -1;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a029407c-3290-4746-90e2-18913651501c | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,348 | supabase-export-v2 | e67ae913ccfd5a65 | Each member definition has a member name, type, offset, access flags and documentation string. See the :ref:`Generic-Attribute-Management` section below for details.
A disadvantage of this approach is that it doesn't provide a way to restrict the
types of objects that can be assigned to the Python attributes. We expect... | trusted_official_docs | CPython Docs | Each member definition has a member name, type, offset, access flags and documentation string. See the :ref:`Generic-Attribute-Management` section below for details.
A disadvantage of this approach is that it doesn't provide a way to restrict the
types of objects that can be assigned to the Python attributes. We expect... | Each member definition has a member name, type, offset, access flags and documentation string. See the :ref:`Generic-Attribute-Management` section below for details.
A disadvantage of this approach is that it doesn't provide a way to restrict the
types of objects that can be assigned to the Python attributes. We expect... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a0bb7d18-5a2e-47b5-b849-bd04352beacd | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,434 | supabase-export-v2 | c4b56e464f389d9f | return 0; }
Before calling :c:func:`PyType_Ready`, the type structure must have the
:c:member:`~PyTypeObject.tp_base` slot filled in. When we are deriving an
existing type, it is not necessary to fill out the :c:member:`~PyTypeObject.tp_alloc`
slot with :c:func:`PyType_GenericNew` -- the allocation function from the ba... | trusted_official_docs | CPython Docs | return 0; }
Before calling :c:func:`PyType_Ready`, the type structure must have the
:c:member:`~PyTypeObject.tp_base` slot filled in. When we are deriving an
existing type, it is not necessary to fill out the :c:member:`~PyTypeObject.tp_alloc`
slot with :c:func:`PyType_GenericNew` -- the allocation function from the ba... | return 0; }
Before calling :c:func:`PyType_Ready`, the type structure must have the
:c:member:`~PyTypeObject.tp_base` slot filled in. When we are deriving an
existing type, it is not necessary to fill out the :c:member:`~PyTypeObject.tp_alloc`
slot with :c:func:`PyType_GenericNew` -- the allocation function from the ba... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a3e19d71-c54b-43eb-b032-cf27ae2e1488 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,435 | supabase-export-v2 | e2e5477d5b7f0214 | existing type, it is not necessary to fill out the :c:member:`~PyTypeObject.tp_alloc` slot with :c:func:`PyType_GenericNew` -- the allocation function from the base type will be inherited.
After that, calling :c:func:`PyType_Ready` and adding the type object to the
module is the same as with the basic :class:`!Custom` ... | trusted_official_docs | CPython Docs | existing type, it is not necessary to fill out the :c:member:`~PyTypeObject.tp_alloc` slot with :c:func:`PyType_GenericNew` -- the allocation function from the base type will be inherited.
After that, calling :c:func:`PyType_Ready` and adding the type object to the
module is the same as with the basic :class:`!Custom` ... | existing type, it is not necessary to fill out the :c:member:`~PyTypeObject.tp_alloc` slot with :c:func:`PyType_GenericNew` -- the allocation function from the base type will be inherited.
After that, calling :c:func:`PyType_Ready` and adding the type object to the
module is the same as with the basic :class:`!Custom` ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a8c49aca-2c4a-497b-a7d8-dd65641b6d8d | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,389 | supabase-export-v2 | 857cdbc908de0f5f | place we can't change these calls is in the ``tp_dealloc`` implementation, where there is the possibility that the initialization of these members failed in ``tp_new``.
We also rename the module initialization function and module name in the
initialization function, as we did before, and we add an extra definition to t... | trusted_official_docs | CPython Docs | place we can't change these calls is in the ``tp_dealloc`` implementation, where there is the possibility that the initialization of these members failed in ``tp_new``.
We also rename the module initialization function and module name in the
initialization function, as we did before, and we add an extra definition to t... | place we can't change these calls is in the ``tp_dealloc`` implementation, where there is the possibility that the initialization of these members failed in ``tp_new``.
We also rename the module initialization function and module name in the
initialization function, as we did before, and we add an extra definition to t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
a9a19252-cc14-4985-ab99-276531a424f3 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,301 | supabase-export-v2 | 5f3c67567918d1d9 | Adding data and methods to the Basic example ============================================
Let's extend the basic example to add some data and methods. Let's also make
the type usable as a base class. We'll create a new module, :mod:`!custom2` that
adds these capabilities: | trusted_official_docs | CPython Docs | Adding data and methods to the Basic example ============================================
Let's extend the basic example to add some data and methods. Let's also make
the type usable as a base class. We'll create a new module, :mod:`!custom2` that
adds these capabilities: | Adding data and methods to the Basic example ============================================
Let's extend the basic example to add some data and methods. Let's also make
the type usable as a base class. We'll create a new module, :mod:`!custom2` that
adds these capabilities: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ac17452e-db33-400c-a0cd-155bd71987cd | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,332 | supabase-export-v2 | 5d5eda1c4afe4477 | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, &first, &last, &self->number)) return -1;
if (first) {
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;
} | trusted_official_docs | CPython Docs | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, &first, &last, &self->number)) return -1;
if (first) {
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;
} | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", kwlist, &first, &last, &self->number)) return -1;
if (first) {
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;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
af5fc39c-dbea-47b5-bcf2-f2d182622956 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,313 | supabase-export-v2 | f768e86c92b7c5a2 | .. note::
The explicit cast to ``CustomObject *`` above is needed because we defined
``Custom_dealloc`` to take a ``PyObject *`` argument, as the ``tp_dealloc``
function pointer expects to receive a ``PyObject *`` argument. By assigning to the ``tp_dealloc`` slot of a type, we declare
that it can only be called with... | trusted_official_docs | CPython Docs | .. note::
The explicit cast to ``CustomObject *`` above is needed because we defined
``Custom_dealloc`` to take a ``PyObject *`` argument, as the ``tp_dealloc``
function pointer expects to receive a ``PyObject *`` argument. By assigning to the ``tp_dealloc`` slot of a type, we declare
that it can only be called with... | .. note::
The explicit cast to ``CustomObject *`` above is needed because we defined
``Custom_dealloc`` to take a ``PyObject *`` argument, as the ``tp_dealloc``
function pointer expects to receive a ``PyObject *`` argument. By assigning to the ``tp_dealloc`` slot of a type, we declare
that it can only be called with... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
af614393-f6af-46fc-abc0-3d35b8535cb6 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,314 | supabase-export-v2 | 6236c62823120056 | it can only be called with instances of our ``CustomObject`` class, so the cast to ``(CustomObject *)`` is safe. This is object-oriented polymorphism, in C!
In existing code, or in previous versions of this tutorial,
you might see similar functions take a pointer to the subtype
object structure (``CustomObject*``) di... | trusted_official_docs | CPython Docs | it can only be called with instances of our ``CustomObject`` class, so the cast to ``(CustomObject *)`` is safe. This is object-oriented polymorphism, in C!
In existing code, or in previous versions of this tutorial,
you might see similar functions take a pointer to the subtype
object structure (``CustomObject*``) di... | it can only be called with instances of our ``CustomObject`` class, so the cast to ``(CustomObject *)`` is safe. This is object-oriented polymorphism, in C!
In existing code, or in previous versions of this tutorial,
you might see similar functions take a pointer to the subtype
object structure (``CustomObject*``) di... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b272328a-0d02-4750-bea7-e979536ec23b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,328 | supabase-export-v2 | 613443cb99835435 | Rather :c:func:`PyType_Ready` fills it for us by inheriting it from our base class, which is :class:`object` by default. Most types use the default allocation strategy.
.. note::
If you are creating a co-operative :c:member:`~PyTypeObject.tp_new` (one
that calls a base type's :c:member:`~PyTypeObject.tp_new` or :meth... | trusted_official_docs | CPython Docs | Rather :c:func:`PyType_Ready` fills it for us by inheriting it from our base class, which is :class:`object` by default. Most types use the default allocation strategy.
.. note::
If you are creating a co-operative :c:member:`~PyTypeObject.tp_new` (one
that calls a base type's :c:member:`~PyTypeObject.tp_new` or :meth... | Rather :c:func:`PyType_Ready` fills it for us by inheriting it from our base class, which is :class:`object` by default. Most types use the default allocation strategy.
.. note::
If you are creating a co-operative :c:member:`~PyTypeObject.tp_new` (one
that calls a base type's :c:member:`~PyTypeObject.tp_new` or :meth... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b2cf9a84-e594-49a9-ac64-5d3294fa442a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,409 | supabase-export-v2 | fd22de8a562213c4 | there is a possibility that the attribute's destructor would call back into code that reads the attribute again (*especially* if there is a reference cycle).
.. note::
You could emulate :c:func:`Py_CLEAR` by writing:: | trusted_official_docs | CPython Docs | there is a possibility that the attribute's destructor would call back into code that reads the attribute again (*especially* if there is a reference cycle).
.. note::
You could emulate :c:func:`Py_CLEAR` by writing:: | there is a possibility that the attribute's destructor would call back into code that reads the attribute again (*especially* if there is a reference cycle).
.. note::
You could emulate :c:func:`Py_CLEAR` by writing:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b3b6f56c-3250-45fe-8d50-91daf5ba0771 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,440 | supabase-export-v2 | 39a4d915341c7189 | normal strings won't call back into our objects, we can't guarantee that deallocating an instance of a string subclass won't call back into our objects.
.. [#] Also, even with our attributes restricted to strings instances, the user
could pass arbitrary :class:`str` subclasses and therefore still create
reference cyc... | trusted_official_docs | CPython Docs | normal strings won't call back into our objects, we can't guarantee that deallocating an instance of a string subclass won't call back into our objects.
.. [#] Also, even with our attributes restricted to strings instances, the user
could pass arbitrary :class:`str` subclasses and therefore still create
reference cyc... | normal strings won't call back into our objects, we can't guarantee that deallocating an instance of a string subclass won't call back into our objects.
.. [#] Also, even with our attributes restricted to strings instances, the user
could pass arbitrary :class:`str` subclasses and therefore still create
reference cyc... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
b90def02-9185-495a-a04d-601c4937aa0d | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,322 | supabase-export-v2 | e3b04097a2b9f9cc | version of the :class:`!Custom` type above. In this case, we use the ``tp_new`` handler to initialize the ``first`` and ``last`` attributes to non-``NULL`` default values.
``tp_new`` is passed the type being instantiated (not necessarily ``CustomType``,
if a subclass is instantiated) and any arguments passed when the t... | trusted_official_docs | CPython Docs | version of the :class:`!Custom` type above. In this case, we use the ``tp_new`` handler to initialize the ``first`` and ``last`` attributes to non-``NULL`` default values.
``tp_new`` is passed the type being instantiated (not necessarily ``CustomType``,
if a subclass is instantiated) and any arguments passed when the t... | version of the :class:`!Custom` type above. In this case, we use the ``tp_new`` handler to initialize the ``first`` and ``last`` attributes to non-``NULL`` default values.
``tp_new`` is passed the type being instantiated (not necessarily ``CustomType``,
if a subclass is instantiated) and any arguments passed when the t... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ba6d45ba-2bc0-40df-8c6b-eb9096c4e1f2 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,255 | supabase-export-v2 | fffeba2e13c7fe38 | typedef struct { PyObject_HEAD } CustomObject;
This is what a Custom object will contain. ``PyObject_HEAD`` is mandatory
at the start of each object struct and defines a field called ``ob_base``
of type :c:type:`PyObject`, containing a pointer to a type object and a
reference count (these can be accessed using the macr... | trusted_official_docs | CPython Docs | typedef struct { PyObject_HEAD } CustomObject;
This is what a Custom object will contain. ``PyObject_HEAD`` is mandatory
at the start of each object struct and defines a field called ``ob_base``
of type :c:type:`PyObject`, containing a pointer to a type object and a
reference count (these can be accessed using the macr... | typedef struct { PyObject_HEAD } CustomObject;
This is what a Custom object will contain. ``PyObject_HEAD`` is mandatory
at the start of each object struct and defines a field called ``ob_base``
of type :c:type:`PyObject`, containing a pointer to a type object and a
reference count (these can be accessed using the macr... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
bb6fd064-dc41-44e7-ae0d-31d08583c93e | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,335 | supabase-export-v2 | 949f31caed3bbb1b | .tp_init = Custom_init,
The :c:member:`~PyTypeObject.tp_init` slot is exposed in Python as the
:meth:`~object.__init__` method. It is used to initialize an object after it's
created. Initializers always accept positional and keyword arguments,
and they should return either ``0`` on success or ``-1`` on error. | trusted_official_docs | CPython Docs | .tp_init = Custom_init,
The :c:member:`~PyTypeObject.tp_init` slot is exposed in Python as the
:meth:`~object.__init__` method. It is used to initialize an object after it's
created. Initializers always accept positional and keyword arguments,
and they should return either ``0`` on success or ``-1`` on error. | .tp_init = Custom_init,
The :c:member:`~PyTypeObject.tp_init` slot is exposed in Python as the
:meth:`~object.__init__` method. It is used to initialize an object after it's
created. Initializers always accept positional and keyword arguments,
and they should return either ``0`` on success or ``-1`` on error. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c13b86b1-5aa8-4a48-a401-3b6015576733 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,361 | supabase-export-v2 | b589a46d7b75af99 | 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 definition::
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | trusted_official_docs | CPython Docs | 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 definition::
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | 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 definition::
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c5f21d80-331a-4f6f-a170-c88d83e2612a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,261 | supabase-export-v2 | 28aa3fbd181e93b2 | { .ob_base = PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "custom.Custom", .tp_doc = PyDoc_STR("Custom objects"), .tp_basicsize = sizeof(CustomObject), .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = PyType_GenericNew, };
.. note::
We recommend using C99-style designated initializers as above, to
avoid listi... | trusted_official_docs | CPython Docs | { .ob_base = PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "custom.Custom", .tp_doc = PyDoc_STR("Custom objects"), .tp_basicsize = sizeof(CustomObject), .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = PyType_GenericNew, };
.. note::
We recommend using C99-style designated initializers as above, to
avoid listi... | { .ob_base = PyVarObject_HEAD_INIT(NULL, 0) .tp_name = "custom.Custom", .tp_doc = PyDoc_STR("Custom objects"), .tp_basicsize = sizeof(CustomObject), .tp_itemsize = 0, .tp_flags = Py_TPFLAGS_DEFAULT, .tp_new = PyType_GenericNew, };
.. note::
We recommend using C99-style designated initializers as above, to
avoid listi... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
c8d8e17f-2dc8-4594-aad3-860daf462854 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,345 | supabase-export-v2 | 46a2a47e9f2260b6 | Py_T_OBJECT_EX, offsetof(CustomObject, first), 0, "first name"}, {"last", Py_T_OBJECT_EX, offsetof(CustomObject, last), 0, "last name"}, {"number", Py_T_INT, offsetof(CustomObject, number), 0, "custom number"}, {NULL} /* Sentinel */ };
and put the definitions in the :c:member:`~PyTypeObject.tp_members` slot:: | trusted_official_docs | CPython Docs | Py_T_OBJECT_EX, offsetof(CustomObject, first), 0, "first name"}, {"last", Py_T_OBJECT_EX, offsetof(CustomObject, last), 0, "last name"}, {"number", Py_T_INT, offsetof(CustomObject, number), 0, "custom number"}, {NULL} /* Sentinel */ };
and put the definitions in the :c:member:`~PyTypeObject.tp_members` slot:: | Py_T_OBJECT_EX, offsetof(CustomObject, first), 0, "first name"}, {"last", Py_T_OBJECT_EX, offsetof(CustomObject, last), 0, "last name"}, {"number", Py_T_INT, offsetof(CustomObject, number), 0, "custom number"}, {NULL} /* Sentinel */ };
and put the definitions in the :c:member:`~PyTypeObject.tp_members` slot:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
cb369936-339a-40bc-a524-543e1e6b1198 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,413 | supabase-export-v2 | 3644dd4528506e86 | zero, we need to untrack the object from the GC by calling :c:func:`PyObject_GC_UnTrack` before clearing members. Here is our reimplemented deallocator using :c:func:`PyObject_GC_UnTrack` and ``Custom_clear``::
static void
Custom_dealloc(PyObject *op)
{
PyObject_GC_UnTrack(op);
(void)Custom_clear(op);
Py_TYPE(op)-... | trusted_official_docs | CPython Docs | zero, we need to untrack the object from the GC by calling :c:func:`PyObject_GC_UnTrack` before clearing members. Here is our reimplemented deallocator using :c:func:`PyObject_GC_UnTrack` and ``Custom_clear``::
static void
Custom_dealloc(PyObject *op)
{
PyObject_GC_UnTrack(op);
(void)Custom_clear(op);
Py_TYPE(op)-... | zero, we need to untrack the object from the GC by calling :c:func:`PyObject_GC_UnTrack` before clearing members. Here is our reimplemented deallocator using :c:func:`PyObject_GC_UnTrack` and ``Custom_clear``::
static void
Custom_dealloc(PyObject *op)
{
PyObject_GC_UnTrack(op);
(void)Custom_clear(op);
Py_TYPE(op)-... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ce0a8759-f336-4e77-a461-65ad0139bf41 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,387 | supabase-export-v2 | 24310681f79f7d5f | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist, &first, &last, &self->number)) return -1;
if (first) {
tmp = self->first;
Py_INCREF(first);
self->first = first;
Py_DECREF(tmp);
}
if (last) {
tmp = self->last;
Py_INCREF(last);
self->last = last;
Py_DECREF(tmp);
}
return 0;
} | trusted_official_docs | CPython Docs | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist, &first, &last, &self->number)) return -1;
if (first) {
tmp = self->first;
Py_INCREF(first);
self->first = first;
Py_DECREF(tmp);
}
if (last) {
tmp = self->last;
Py_INCREF(last);
self->last = last;
Py_DECREF(tmp);
}
return 0;
} | if (!PyArg_ParseTupleAndKeywords(args, kwds, "|UUi", kwlist, &first, &last, &self->number)) return -1;
if (first) {
tmp = self->first;
Py_INCREF(first);
self->first = first;
Py_DECREF(tmp);
}
if (last) {
tmp = self->last;
Py_INCREF(last);
self->last = last;
Py_DECREF(tmp);
}
return 0;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d17a8190-01df-46a2-b437-b66a35dfd928 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,363 | supabase-export-v2 | da5ff5b9924e3367 | We rename :c:func:`!PyInit_custom` to :c:func:`!PyInit_custom2`, update the module name in the :c:type:`PyModuleDef` struct, and update the full class name in the :c:type:`PyTypeObject` struct.
Finally, we update our :file:`setup.py` file to include the new module, | trusted_official_docs | CPython Docs | We rename :c:func:`!PyInit_custom` to :c:func:`!PyInit_custom2`, update the module name in the :c:type:`PyModuleDef` struct, and update the full class name in the :c:type:`PyTypeObject` struct.
Finally, we update our :file:`setup.py` file to include the new module, | We rename :c:func:`!PyInit_custom` to :c:func:`!PyInit_custom2`, update the module name in the :c:type:`PyModuleDef` struct, and update the full class name in the :c:type:`PyTypeObject` struct.
Finally, we update our :file:`setup.py` file to include the new module, | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d21f3e7c-b054-466d-bf7d-0d7515b30a0b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,350 | supabase-export-v2 | d7674a46f4156cda | We define a single method, :meth:`!Custom.name`, that outputs the objects name as the concatenation of the first and last names. ::
static PyObject *
Custom_name(PyObject *op, PyObject *Py_UNUSED(dummy))
{
CustomObject *self = (CustomObject *) op;
if (self->first == NULL) {
PyErr_SetString(PyExc_AttributeError, "f... | trusted_official_docs | CPython Docs | We define a single method, :meth:`!Custom.name`, that outputs the objects name as the concatenation of the first and last names. ::
static PyObject *
Custom_name(PyObject *op, PyObject *Py_UNUSED(dummy))
{
CustomObject *self = (CustomObject *) op;
if (self->first == NULL) {
PyErr_SetString(PyExc_AttributeError, "f... | We define a single method, :meth:`!Custom.name`, that outputs the objects name as the concatenation of the first and last names. ::
static PyObject *
Custom_name(PyObject *op, PyObject *Py_UNUSED(dummy))
{
CustomObject *self = (CustomObject *) op;
if (self->first == NULL) {
PyErr_SetString(PyExc_AttributeError, "f... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d2849942-3e9b-4c4f-a125-7eaef8dc9c61 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,394 | supabase-export-v2 | aec71e4a9f51046c | >>> l = [] >>> l.append(l) >>> del l
In this example, we create a list that contains itself. When we delete it, it
still has a reference from itself. Its reference count doesn't drop to zero. Fortunately, Python's cyclic garbage collector will eventually figure out that
the list is garbage and free it. | trusted_official_docs | CPython Docs | >>> l = [] >>> l.append(l) >>> del l
In this example, we create a list that contains itself. When we delete it, it
still has a reference from itself. Its reference count doesn't drop to zero. Fortunately, Python's cyclic garbage collector will eventually figure out that
the list is garbage and free it. | >>> l = [] >>> l.append(l) >>> del l
In this example, we create a list that contains itself. When we delete it, it
still has a reference from itself. Its reference count doesn't drop to zero. Fortunately, Python's cyclic garbage collector will eventually figure out that
the list is garbage and free it. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d5e01780-61fa-447e-ad81-63624ccc5f57 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,377 | supabase-export-v2 | f77e0183c2af444a | attribute is being deleted. In our setter, we raise an error if the attribute is deleted or if its new value is not a string.
We create an array of :c:type:`PyGetSetDef` structures:: | trusted_official_docs | CPython Docs | attribute is being deleted. In our setter, we raise an error if the attribute is deleted or if its new value is not a string.
We create an array of :c:type:`PyGetSetDef` structures:: | attribute is being deleted. In our setter, we raise an error if the attribute is deleted or if its new value is not a string.
We create an array of :c:type:`PyGetSetDef` structures:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d732b58e-71f7-46d5-9304-fa2ebbc8b657 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,330 | supabase-export-v2 | 2176e7ef94f333c1 | We also define an initialization function which accepts arguments to provide initial values for our instance::
static int
Custom_init(PyObject *op, PyObject *args, PyObject *kwds)
{
CustomObject *self = (CustomObject *) op;
static char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = ... | trusted_official_docs | CPython Docs | We also define an initialization function which accepts arguments to provide initial values for our instance::
static int
Custom_init(PyObject *op, PyObject *args, PyObject *kwds)
{
CustomObject *self = (CustomObject *) op;
static char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = ... | We also define an initialization function which accepts arguments to provide initial values for our instance::
static int
Custom_init(PyObject *op, PyObject *args, PyObject *kwds)
{
CustomObject *self = (CustomObject *) op;
static char *kwlist[] = {"first", "last", "number", NULL};
PyObject *first = NULL, *last = ... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d78e4757-77e3-418c-b16f-4be830b1b69f | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,247 | supabase-export-v2 | 1ecedf31a27b2987 | an attribute gets looked up on an object, a method called, or it is multiplied by another object. These C functions are called "type methods".
So, if you want to define a new extension type, you need to create a new type
object. | trusted_official_docs | CPython Docs | an attribute gets looked up on an object, a method called, or it is multiplied by another object. These C functions are called "type methods".
So, if you want to define a new extension type, you need to create a new type
object. | an attribute gets looked up on an object, a method called, or it is multiplied by another object. These C functions are called "type methods".
So, if you want to define a new extension type, you need to create a new type
object. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
d8fb9c91-ffc0-43a1-941b-8496e0209226 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,248 | supabase-export-v2 | 9136add810b1874e | So, if you want to define a new extension type, you need to create a new type object.
This sort of thing can only be explained by example, so here's a minimal, but
complete, module that defines a new type named :class:`!Custom` inside a C
extension module :mod:`!custom`: | trusted_official_docs | CPython Docs | So, if you want to define a new extension type, you need to create a new type object.
This sort of thing can only be explained by example, so here's a minimal, but
complete, module that defines a new type named :class:`!Custom` inside a C
extension module :mod:`!custom`: | So, if you want to define a new extension type, you need to create a new type object.
This sort of thing can only be explained by example, so here's a minimal, but
complete, module that defines a new type named :class:`!Custom` inside a C
extension module :mod:`!custom`: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
dba1bc7f-2d38-4df5-b01f-9515d306a9df | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,404 | supabase-export-v2 | 9816decb93bb6afe | Python provides a :c:func:`Py_VISIT` macro that automates calling visit functions. With :c:func:`Py_VISIT`, we can minimize the amount of boilerplate in ``Custom_traverse``::
static int
Custom_traverse(PyObject *op, visitproc visit, void *arg)
{
CustomObject *self = (CustomObject *) op;
Py_VISIT(self->first);
Py_V... | trusted_official_docs | CPython Docs | Python provides a :c:func:`Py_VISIT` macro that automates calling visit functions. With :c:func:`Py_VISIT`, we can minimize the amount of boilerplate in ``Custom_traverse``::
static int
Custom_traverse(PyObject *op, visitproc visit, void *arg)
{
CustomObject *self = (CustomObject *) op;
Py_VISIT(self->first);
Py_V... | Python provides a :c:func:`Py_VISIT` macro that automates calling visit functions. With :c:func:`Py_VISIT`, we can minimize the amount of boilerplate in ``Custom_traverse``::
static int
Custom_traverse(PyObject *op, visitproc visit, void *arg)
{
CustomObject *self = (CustomObject *) op;
Py_VISIT(self->first);
Py_V... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e2233d60-f50e-4b0e-8f14-0792c49611b8 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,357 | supabase-export-v2 | 177a82314597c577 | static PyMethodDef Custom_methods[] = { {"name", Custom_name, METH_NOARGS, "Return the name, combining the first and last name" }, {NULL} /* Sentinel */ };
(note that we used the :c:macro:`METH_NOARGS` flag to indicate that the method
is expecting no arguments other than *self*) | trusted_official_docs | CPython Docs | static PyMethodDef Custom_methods[] = { {"name", Custom_name, METH_NOARGS, "Return the name, combining the first and last name" }, {NULL} /* Sentinel */ };
(note that we used the :c:macro:`METH_NOARGS` flag to indicate that the method
is expecting no arguments other than *self*) | static PyMethodDef Custom_methods[] = { {"name", Custom_name, METH_NOARGS, "Return the name, combining the first and last name" }, {NULL} /* Sentinel */ };
(note that we used the :c:macro:`METH_NOARGS` flag to indicate that the method
is expecting no arguments other than *self*) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e26c2950-985d-4574-8aeb-11e50f36fc09 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,323 | supabase-export-v2 | 3980c082b4de3600 | positional and keyword arguments, but they often ignore the arguments, leaving the argument handling to initializer (a.k.a. ``tp_init`` in C or ``__init__`` in Python) methods.
.. note::
``tp_new`` shouldn't call ``tp_init`` explicitly, as the interpreter
will do it itself. | trusted_official_docs | CPython Docs | positional and keyword arguments, but they often ignore the arguments, leaving the argument handling to initializer (a.k.a. ``tp_init`` in C or ``__init__`` in Python) methods.
.. note::
``tp_new`` shouldn't call ``tp_init`` explicitly, as the interpreter
will do it itself. | positional and keyword arguments, but they often ignore the arguments, leaving the argument handling to initializer (a.k.a. ``tp_init`` in C or ``__init__`` in Python) methods.
.. note::
``tp_new`` shouldn't call ``tp_init`` explicitly, as the interpreter
will do it itself. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e78e61c1-d2a6-437b-9aed-7971f3b81ff4 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,329 | supabase-export-v2 | c4537337fc3e8481 | inherit from other Python-defined classes may not work correctly. (Specifically, you may not be able to create instances of such subclasses without getting a :exc:`TypeError`.)
We also define an initialization function which accepts arguments to provide
initial values for our instance:: | trusted_official_docs | CPython Docs | inherit from other Python-defined classes may not work correctly. (Specifically, you may not be able to create instances of such subclasses without getting a :exc:`TypeError`.)
We also define an initialization function which accepts arguments to provide
initial values for our instance:: | inherit from other Python-defined classes may not work correctly. (Specifically, you may not be able to create instances of such subclasses without getting a :exc:`TypeError`.)
We also define an initialization function which accepts arguments to provide
initial values for our instance:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
e9bb7389-e835-4fb6-89ae-dd8413f3c26b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,419 | supabase-export-v2 | 4e016ea3839a689a | 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 between extension modules.
In this example we will create a :class:`!SubList` type that inherits from the
built-in :class:`list` type. The new type will be complete... | trusted_official_docs | CPython Docs | 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 between extension modules.
In this example we will create a :class:`!SubList` type that inherits from the
built-in :class:`list` type. The new type will be complete... | 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 between extension modules.
In this example we will create a :class:`!SubList` type that inherits from the
built-in :class:`list` type. The new type will be complete... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
eb857c11-ff9b-4911-852e-890b985c4eda | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,331 | supabase-export-v2 | 559e54be89c461f4 | PyObject *kwds) { CustomObject *self = (CustomObject *) op; static char *kwlist[] = {"first", "last", "number", NULL}; PyObject *first = NULL, *last = NULL, *tmp;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi", 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, "|OOi", 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, "|OOi", kwlist,
&first, &last,
&self->number))
return -1; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ebc0a68f-94f4-488b-b33c-c98bb9fc7c47 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,384 | supabase-export-v2 | a4caab32ee7a4ff8 | static PyMemberDef Custom_members[] = { {"number", Py_T_INT, offsetof(CustomObject, number), 0, "custom number"}, {NULL} /* Sentinel */ };
We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only
allow strings [#]_ to be passed:: | trusted_official_docs | CPython Docs | static PyMemberDef Custom_members[] = { {"number", Py_T_INT, offsetof(CustomObject, number), 0, "custom number"}, {NULL} /* Sentinel */ };
We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only
allow strings [#]_ to be passed:: | static PyMemberDef Custom_members[] = { {"number", Py_T_INT, offsetof(CustomObject, number), 0, "custom number"}, {NULL} /* Sentinel */ };
We also need to update the :c:member:`~PyTypeObject.tp_init` handler to only
allow strings [#]_ to be passed:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ec1b13dc-10d0-444a-9edf-0b3eb63cf741 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,416 | supabase-export-v2 | 2211e692ce801ffb | .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
That's pretty much it. If we had written custom :c:member:`~PyTypeObject.tp_alloc` or
:c:member:`~PyTypeObject.tp_free` handlers, we'd need to modify them for cyclic
garbage collection. Most extensions will use the versions automatically provide... | trusted_official_docs | CPython Docs | .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
That's pretty much it. If we had written custom :c:member:`~PyTypeObject.tp_alloc` or
:c:member:`~PyTypeObject.tp_free` handlers, we'd need to modify them for cyclic
garbage collection. Most extensions will use the versions automatically provide... | .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
That's pretty much it. If we had written custom :c:member:`~PyTypeObject.tp_alloc` or
:c:member:`~PyTypeObject.tp_free` handlers, we'd need to modify them for cyclic
garbage collection. Most extensions will use the versions automatically provide... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ed570847-9ed1-4f2c-9804-7c449fc9c42b | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,342 | supabase-export-v2 | e6494c4629379ccf | know that deallocation of the object [#]_ will neither detach the :term:`thread state <attached thread state>` nor cause any calls back into our type's code;
* when decrementing a reference count in a :c:member:`~PyTypeObject.tp_dealloc`
handler on a type which doesn't support cyclic garbage collection [#]_. | trusted_official_docs | CPython Docs | know that deallocation of the object [#]_ will neither detach the :term:`thread state <attached thread state>` nor cause any calls back into our type's code;
* when decrementing a reference count in a :c:member:`~PyTypeObject.tp_dealloc`
handler on a type which doesn't support cyclic garbage collection [#]_. | know that deallocation of the object [#]_ will neither detach the :term:`thread state <attached thread state>` nor cause any calls back into our type's code;
* when decrementing a reference count in a :c:member:`~PyTypeObject.tp_dealloc`
handler on a type which doesn't support cyclic garbage collection [#]_. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
eedc1dec-6217-4131-a93a-20ba1cd0bbf4 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,321 | supabase-export-v2 | 451f52a08ce639ce | .tp_new = Custom_new,
The ``tp_new`` handler is responsible for creating (as opposed to initializing)
objects of the type. It is exposed in Python as the :meth:`~object.__new__` method. It is not required to define a ``tp_new`` member, and indeed many extension
types will simply reuse :c:func:`PyType_GenericNew` as don... | trusted_official_docs | CPython Docs | .tp_new = Custom_new,
The ``tp_new`` handler is responsible for creating (as opposed to initializing)
objects of the type. It is exposed in Python as the :meth:`~object.__new__` method. It is not required to define a ``tp_new`` member, and indeed many extension
types will simply reuse :c:func:`PyType_GenericNew` as don... | .tp_new = Custom_new,
The ``tp_new`` handler is responsible for creating (as opposed to initializing)
objects of the type. It is exposed in Python as the :meth:`~object.__new__` method. It is not required to define a ``tp_new`` member, and indeed many extension
types will simply reuse :c:func:`PyType_GenericNew` as don... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ef7f6406-a8b6-457c-a0ad-7a1d63c5deb1 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,430 | supabase-export-v2 | 0daa9d63a3fd9cc0 | handler should not actually create the memory for the object with its :c:member:`~PyTypeObject.tp_alloc`, but let the base class handle it by calling its own :c:member:`~PyTypeObject.tp_new`.
The :c:type:`PyTypeObject` struct supports a :c:member:`~PyTypeObject.tp_base`
specifying the type's concrete base class. Due to... | trusted_official_docs | CPython Docs | handler should not actually create the memory for the object with its :c:member:`~PyTypeObject.tp_alloc`, but let the base class handle it by calling its own :c:member:`~PyTypeObject.tp_new`.
The :c:type:`PyTypeObject` struct supports a :c:member:`~PyTypeObject.tp_base`
specifying the type's concrete base class. Due to... | handler should not actually create the memory for the object with its :c:member:`~PyTypeObject.tp_alloc`, but let the base class handle it by calling its own :c:member:`~PyTypeObject.tp_new`.
The :c:type:`PyTypeObject` struct supports a :c:member:`~PyTypeObject.tp_base`
specifying the type's concrete base class. Due to... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f01e1c46-4d7e-4b4f-af09-e6a6c08534b4 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,411 | supabase-export-v2 | 149cc777b7c84f28 | PyObject *tmp; tmp = self->first; self->first = NULL; Py_XDECREF(tmp);
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! | trusted_official_docs | CPython Docs | PyObject *tmp; tmp = self->first; self->first = NULL; Py_XDECREF(tmp);
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! | PyObject *tmp; tmp = self->first; self->first = NULL; Py_XDECREF(tmp);
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! | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f7110f52-c547-4d07-bf7e-400c906a70b7 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,341 | supabase-export-v2 | a20e6a0e35b83da2 | * when we absolutely know that the reference count is greater than 1;
* when we know that deallocation of the object [#]_ will neither detach
the :term:`thread state <attached thread state>` nor cause any calls back into our type's code; | trusted_official_docs | CPython Docs | * when we absolutely know that the reference count is greater than 1;
* when we know that deallocation of the object [#]_ will neither detach
the :term:`thread state <attached thread state>` nor cause any calls back into our type's code; | * when we absolutely know that the reference count is greater than 1;
* when we know that deallocation of the object [#]_ will neither detach
the :term:`thread state <attached thread state>` nor cause any calls back into our type's code; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
f9aae7f6-4d9c-4248-a794-8ca6583c4897 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,305 | supabase-export-v2 | 7d9406068da6d663 | struct, *first*, *last*, and *number*. The *first* and *last* variables are Python strings containing first and last names. The *number* attribute is a C integer.
The object structure is updated accordingly:: | trusted_official_docs | CPython Docs | struct, *first*, *last*, and *number*. The *first* and *last* variables are Python strings containing first and last names. The *number* attribute is a C integer.
The object structure is updated accordingly:: | struct, *first*, *last*, and *number*. The *first* and *last* variables are Python strings containing first and last names. The *number* attribute is a C integer.
The object structure is updated accordingly:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fa6023d3-a0b0-4b95-bdb1-8d52dc4e02c3 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,431 | supabase-export-v2 | 9fd97367df303027 | class. Due to cross-platform compiler issues, you can't fill that field directly with a reference to :c:type:`PyList_Type`; it should be done in the :c:data:`Py_mod_exec` function::
static int
sublist_module_exec(PyObject *m)
{
SubListType.tp_base = &PyList_Type;
if (PyType_Ready(&SubListType) < 0) {
return -1;
} | trusted_official_docs | CPython Docs | class. Due to cross-platform compiler issues, you can't fill that field directly with a reference to :c:type:`PyList_Type`; it should be done in the :c:data:`Py_mod_exec` function::
static int
sublist_module_exec(PyObject *m)
{
SubListType.tp_base = &PyList_Type;
if (PyType_Ready(&SubListType) < 0) {
return -1;
} | class. Due to cross-platform compiler issues, you can't fill that field directly with a reference to :c:type:`PyList_Type`; it should be done in the :c:data:`Py_mod_exec` function::
static int
sublist_module_exec(PyObject *m)
{
SubListType.tp_base = &PyList_Type;
if (PyType_Ready(&SubListType) < 0) {
return -1;
} | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
fbb1d113-82a5-439e-b788-122155071575 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,286 | supabase-export-v2 | 8cbe1635a30392ae | if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) { return -1; }
This adds the type to the module dictionary. This allows us to create
:class:`!Custom` instances by calling the :class:`!Custom` class: | trusted_official_docs | CPython Docs | if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) { return -1; }
This adds the type to the module dictionary. This allows us to create
:class:`!Custom` instances by calling the :class:`!Custom` class: | if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) { return -1; }
This adds the type to the module dictionary. This allows us to create
:class:`!Custom` instances by calling the :class:`!Custom` class: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
feca4bbd-85b5-4e98-8d26-9c711432eb52 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,317 | supabase-export-v2 | 147328bc382cae37 | This does the same thing on all architectures that CPython supports, but according to the C standard, it invokes undefined behavior.
We want to make sure that the first and last names are initialized to empty
strings, so we provide a ``tp_new`` implementation:: | trusted_official_docs | CPython Docs | This does the same thing on all architectures that CPython supports, but according to the C standard, it invokes undefined behavior.
We want to make sure that the first and last names are initialized to empty
strings, so we provide a ``tp_new`` implementation:: | This does the same thing on all architectures that CPython supports, but according to the C standard, it invokes undefined behavior.
We want to make sure that the first and last names are initialized to empty
strings, so we provide a ``tp_new`` implementation:: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ff6e201f-cc89-481c-a8d6-fb979481657a | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,425 | supabase-export-v2 | ae2fb7d03947490b | typedef struct { PyListObject list; int state; } SubListObject;
The primary difference for derived type objects is 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. | trusted_official_docs | CPython Docs | typedef struct { PyListObject list; int state; } SubListObject;
The primary difference for derived type objects is 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. | typedef struct { PyListObject list; int state; } SubListObject;
The primary difference for derived type objects is 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. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
ffc693b5-9257-4b6b-a579-b1ad14fc8982 | CPython Docs | file://datasets/cpython/Doc/extending/newtypes_tutorial.rst | unknown | e371830d-1e8c-49b8-aa91-454b02759c25 | 1,424 | supabase-export-v2 | 7ca795d3ab630031 | As you can see, the source code closely resembles the :class:`!Custom` examples in previous sections. We will break down the main differences between them. ::
typedef struct {
PyListObject list;
int state;
} SubListObject; | trusted_official_docs | CPython Docs | As you can see, the source code closely resembles the :class:`!Custom` examples in previous sections. We will break down the main differences between them. ::
typedef struct {
PyListObject list;
int state;
} SubListObject; | As you can see, the source code closely resembles the :class:`!Custom` examples in previous sections. We will break down the main differences between them. ::
typedef struct {
PyListObject list;
int state;
} SubListObject; | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
04aed97e-c0b3-4d2b-8691-b94bd9877b67 | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,450 | supabase-export-v2 | 0d5e50bcd3b2601d | Very High Level Embedding =========================
The simplest form of embedding Python is the use of the very high level
interface. This interface is intended to execute a Python script without needing
to interact with the application directly. This can for example be used to
perform some operation on a file. :: | trusted_official_docs | CPython Docs | Very High Level Embedding =========================
The simplest form of embedding Python is the use of the very high level
interface. This interface is intended to execute a Python script without needing
to interact with the application directly. This can for example be used to
perform some operation on a file. :: | Very High Level Embedding =========================
The simplest form of embedding Python is the use of the very high level
interface. This interface is intended to execute a Python script without needing
to interact with the application directly. This can for example be used to
perform some operation on a file. :: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
093aacef-238c-4909-84a3-0f1170be49c1 | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,458 | supabase-export-v2 | 03d9a70260d95eca | .. note::
``#define PY_SSIZE_T_CLEAN`` was used to indicate that ``Py_ssize_t`` should be
used in some APIs instead of ``int``. It is not necessary since Python 3.13, but we keep it here for backward compatibility. See :ref:`arg-parsing-string-and-buffers` for a description of this macro. | trusted_official_docs | CPython Docs | .. note::
``#define PY_SSIZE_T_CLEAN`` was used to indicate that ``Py_ssize_t`` should be
used in some APIs instead of ``int``. It is not necessary since Python 3.13, but we keep it here for backward compatibility. See :ref:`arg-parsing-string-and-buffers` for a description of this macro. | .. note::
``#define PY_SSIZE_T_CLEAN`` was used to indicate that ``Py_ssize_t`` should be
used in some APIs instead of ``int``. It is not necessary since Python 3.13, but we keep it here for backward compatibility. See :ref:`arg-parsing-string-and-buffers` for a description of this macro. | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
316e8438-0d02-4376-b98c-03bb19ca0da6 | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,443 | supabase-export-v2 | bb111b64c05e0968 | needs by writing some scripts in Python. You can also use it yourself if some of the functionality can be written in Python more easily.
Embedding Python is similar to extending it, but not quite. The difference is
that when you extend Python, the main program of the application is still the
Python interpreter, while i... | trusted_official_docs | CPython Docs | needs by writing some scripts in Python. You can also use it yourself if some of the functionality can be written in Python more easily.
Embedding Python is similar to extending it, but not quite. The difference is
that when you extend Python, the main program of the application is still the
Python interpreter, while i... | needs by writing some scripts in Python. You can also use it yourself if some of the functionality can be written in Python more easily.
Embedding Python is similar to extending it, but not quite. The difference is
that when you extend Python, the main program of the application is still the
Python interpreter, while i... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
33c50e5e-b1cc-4757-99c9-51200d9aa341 | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,511 | supabase-export-v2 | 5c7ac17fbf1c6acc | Compiling and Linking under Unix-like systems =============================================
It is not necessarily trivial to find the right flags to pass to your
compiler (and linker) in order to embed the Python interpreter into your
application, particularly because Python needs to load library modules
implemented as... | trusted_official_docs | CPython Docs | Compiling and Linking under Unix-like systems =============================================
It is not necessarily trivial to find the right flags to pass to your
compiler (and linker) in order to embed the Python interpreter into your
application, particularly because Python needs to load library modules
implemented as... | Compiling and Linking under Unix-like systems =============================================
It is not necessarily trivial to find the right flags to pass to your
compiler (and linker) in order to embed the Python interpreter into your
application, particularly because Python needs to load library modules
implemented as... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
460b4ec1-ad1e-4549-b52f-9afcd3db09c7 | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,519 | supabase-export-v2 | 5c8c1796ca467bd0 | $ /opt/bin/python3.11-config --ldflags --embed -L/opt/lib/python3.11/config-3.11-x86_64-linux-gnu -L/opt/lib -lpython3.11 -lpthread -ldl -lutil -lm
.. note::
To avoid confusion between several Python installations (and especially
between the system Python and your own compiled Python), it is recommended
that you use... | trusted_official_docs | CPython Docs | $ /opt/bin/python3.11-config --ldflags --embed -L/opt/lib/python3.11/config-3.11-x86_64-linux-gnu -L/opt/lib -lpython3.11 -lpthread -ldl -lutil -lm
.. note::
To avoid confusion between several Python installations (and especially
between the system Python and your own compiled Python), it is recommended
that you use... | $ /opt/bin/python3.11-config --ldflags --embed -L/opt/lib/python3.11/config-3.11-x86_64-linux-gnu -L/opt/lib -lpython3.11 -lpthread -ldl -lutil -lm
.. note::
To avoid confusion between several Python installations (and especially
between the system Python and your own compiled Python), it is recommended
that you use... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4a52a620-cc37-4010-8261-a0c76a791edc | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,513 | supabase-export-v2 | d23de1940f415fe4 | the installation process (a :file:`python3-config` script may also be available). This script has several options, of which the following will be directly useful to you:
* ``pythonX.Y-config --cflags`` will give you the recommended flags when
compiling: | trusted_official_docs | CPython Docs | the installation process (a :file:`python3-config` script may also be available). This script has several options, of which the following will be directly useful to you:
* ``pythonX.Y-config --cflags`` will give you the recommended flags when
compiling: | the installation process (a :file:`python3-config` script may also be available). This script has several options, of which the following will be directly useful to you:
* ``pythonX.Y-config --cflags`` will give you the recommended flags when
compiling: | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4a7796cf-2a55-4302-845f-fbdb1e62d90b | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,485 | supabase-export-v2 | f0aeee7a83b78cc3 | Py_Initialize(); pName = PyUnicode_DecodeFSDefault(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName);
After initializing the interpreter, the script is loaded using
:c:func:`PyImport_Import`. This routine needs a Python string as its argument,
which is constructed using the :c:func:`PyUn... | trusted_official_docs | CPython Docs | Py_Initialize(); pName = PyUnicode_DecodeFSDefault(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName);
After initializing the interpreter, the script is loaded using
:c:func:`PyImport_Import`. This routine needs a Python string as its argument,
which is constructed using the :c:func:`PyUn... | Py_Initialize(); pName = PyUnicode_DecodeFSDefault(argv[1]); /* Error checking of pName left out */ pModule = PyImport_Import(pName);
After initializing the interpreter, the script is loaded using
:c:func:`PyImport_Import`. This routine needs a Python string as its argument,
which is constructed using the :c:func:`PyUn... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
4b9820de-4c3e-436a-a082-5b9cdc55bda3 | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,512 | supabase-export-v2 | a708ce19a0afb778 | embed the Python interpreter into your application, particularly because Python needs to load library modules implemented as C dynamic extensions (:file:`.so` files) linked against it.
To find out the required compiler and linker flags, you can execute the
:file:`python{X.Y}-config` script which is generated as part of... | trusted_official_docs | CPython Docs | embed the Python interpreter into your application, particularly because Python needs to load library modules implemented as C dynamic extensions (:file:`.so` files) linked against it.
To find out the required compiler and linker flags, you can execute the
:file:`python{X.Y}-config` script which is generated as part of... | embed the Python interpreter into your application, particularly because Python needs to load library modules implemented as C dynamic extensions (:file:`.so` files) linked against it.
To find out the required compiler and linker flags, you can execute the
:file:`python{X.Y}-config` script which is generated as part of... | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5ec54078-262b-4cba-b731-55000804167a | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,505 | supabase-export-v2 | 7007b85837950d8a | In a real application, the methods will expose an API of the application to Python.
.. TODO: threads, code examples do not really behave well if errors happen
(what to watch out for) | trusted_official_docs | CPython Docs | In a real application, the methods will expose an API of the application to Python.
.. TODO: threads, code examples do not really behave well if errors happen
(what to watch out for) | In a real application, the methods will expose an API of the application to Python.
.. TODO: threads, code examples do not really behave well if errors happen
(what to watch out for) | python, official-docs, cpython, P0 | Local_Trusted_Corpus | |
5fbb8f10-f26e-414f-b6e2-c881a3f20231 | CPython Docs | file://datasets/cpython/Doc/extending/embedding.rst | unknown | 3dadfc00-38ea-4a45-841b-b4dc3757dc7e | 1,520 | supabase-export-v2 | 9bbecdf4fd0fc464 | between the system Python and your own compiled Python), it is recommended that you use the absolute path to :file:`python{X.Y}-config`, as in the above example.
If this procedure doesn't work for you (it is not guaranteed to work for
all Unix-like platforms; however, we welcome :ref:`bug reports <reporting-bugs>`)
you... | trusted_official_docs | CPython Docs | between the system Python and your own compiled Python), it is recommended that you use the absolute path to :file:`python{X.Y}-config`, as in the above example.
If this procedure doesn't work for you (it is not guaranteed to work for
all Unix-like platforms; however, we welcome :ref:`bug reports <reporting-bugs>`)
you... | between the system Python and your own compiled Python), it is recommended that you use the absolute path to :file:`python{X.Y}-config`, as in the above example.
If this procedure doesn't work for you (it is not guaranteed to work for
all Unix-like platforms; however, we welcome :ref:`bug reports <reporting-bugs>`)
you... | 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.