The int type in python offers two attributes named numerator and real that have the same content as __int__().
As all of these 3 values returns the same internal attribute, I guess real is a property like:
@property
def real(self):
return self.__int
However I cannot find this hidden property dir dir or either a = int(); a._int__<tab> in IPython.
So I looked at the source code and found this:
static PyGetSetDef int_getset[] = {
{"real",
(getter)int_int, (setter)NULL,
"the real part of a complex number",
NULL},
{"imag",
(getter)int_get0, (setter)NULL,
"the imaginary part of a complex number",
NULL},
{"numerator",
(getter)int_int, (setter)NULL,
"the numerator of a rational number in lowest terms",
NULL},
{"denominator",
(getter)int_get1, (setter)NULL,
"the denominator of a rational number in lowest terms",
NULL},
{NULL} /* Sentinel */
};
And this:
static PyObject *
int_int(PyIntObject *v)
{
if (PyInt_CheckExact(v))
Py_INCREF(v);
else
v = (PyIntObject *)PyInt_FromLong(v->ob_ival);
return (PyObject *)v;
}
But this the furthest I can go by myself.
Where the actual value of an integer is stored inside an integer instance?
The main reason for this question is that I want to extend the float type with a MyFloat where I would like to refer to the value of the instance.