The int type in python offers two attributes named numerator and real , which have the same content as __int__() .
Since all these 3 values ββreturn the same internal attribute, I think real is a property like this:
@property def real(self): return self.__int
However, I cannot find this hidden property dir dir or either a = int(); a._int__<tab> 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} };
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 is the further that I can do myself.
Where is the actual value of an integer stored inside an integer instance?
The main reason for this question is because I want to extend the float type to MyFloat , where I would like to refer to the value of the instance.