I was looking at types.py to understand the built-in types and I came across this GetSetDescriptorType. From the Python documentation:
types.GetSetDescriptorType
The type of objects defined in extension modules with PyGetSetDef,
such as FrameType.f_locals or array.array.typecode. This type is used
as descriptor for object attributes; it has the same purpose as the
property type, but for classes defined in extension modules
I do understand the property type, but could not wrap my mind around this. Can some one who understands this throw some light ?
When you write a Python module using C, you define new types using a C API. This API has a lot of functions and structs to specify all the behavior of the new type.
One way to specify properties of a type using the C API is to define an array of
PyGetSetDefstructs:And then use the array in the initialization of the type (see this example for details).
Then, in Python, when you use
MyType.my_propertyyou have a value oftypes.GetSetDescriptorType, that is used to resolve the actual value of the property when you writemy_obj.my_property.As such, this type is an implementation detail, unlikely to be very useful.