Defining Extension Types: Assorted Topics — Python 3.16.0a0 documentation

docs.python.org

Tin mới

Defining Extension Types: Tutorial

Building C and C++ Extensions

Python Module Index

3.16.0a0 Documentation

Extending and Embedding the Python Interpreter

Finalization and De-allocation¶

This section aims to give a quick fly-by on the various type methods you can implement and what they do.

Finalization and De-allocation¶

This section aims to give a quick fly-by on the various type methods you can implement and what they do.

PyTypeObject.tp_itemsize

This section aims to give a quick fly-by on the various type methods you can implement and what they do.

PyObject_GC_UnTrack()

This function is called when the reference count of the instance of your type is reduced to zero and the Python interpreter wants to reclaim it. If your type has memory to free or other clean-up to perform, you can put i

Finalization and De-allocation¶

This function is called when the reference count of the instance of your type is reduced to zero and the Python interpreter wants to reclaim it. If your type has memory to free or other clean-up to perform, you can put i

Object Presentation¶

In Python, there are two ways to generate a textual representation of an object: the repr() function, and the str() function. (The print() function just calls str().) These handlers are both optional.

Object Presentation¶

In Python, there are two ways to generate a textual representation of an object: the repr() function, and the str() function. (The print() function just calls str().) These handlers are both optional.

Generic Attribute Management¶

Most extension types only use simple attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:

Generic Attribute Management¶

Most extension types only use simple attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:

Generic Attribute Management¶

Most extension types only use simple attributes. So, what makes the attributes simple? There are only a couple of conditions that must be met:

PyObject_RichCompare()

The tp_richcompare handler is called when comparisons are needed. It is analogous to the rich comparison methods, like __lt__(), and also called by PyObject_RichCompare() and PyObject_RichCompareBool().

Abstract Objects Layer

Python supports a variety of abstract ‘protocols;’ the specific interfaces provided to use these interfaces are documented in Abstract Objects Layer.

Abstract Protocol Support¶

Python supports a variety of abstract ‘protocols;’ the specific interfaces provided to use these interfaces are documented in Abstract Objects Layer.

PyArg_ParseTuple()

args is a tuple containing the arguments to the call. You can use PyArg_ParseTuple() to extract the arguments.

Abstract Protocol Support¶

Python supports a variety of abstract ‘protocols;’ the specific interfaces provided to use these interfaces are documented in Abstract Objects Layer.

weakref: Support for weak references and weak dictionaries.

PyObject_ClearWeakRefs()

One of the goals of Python’s weak reference implementation is to allow any type to participate in the weak reference mechanism without incurring the overhead on performance-critical objects (such as numbers).