CPython internal design question

Tim Peters tim.one at home.com
Fri Dec 14 17:35:40 EST 2001


[Courageous]
> The various different internal structures of python use
> a definition strategy like this:
>
> typedef struct {
>     PyObject_HEAD
>     PyObject *im_func;        /* The callable object implementing
> the method */
>     PyObject *im_self;        /* The instance it is bound to, or NULL */
>     PyObject *im_class;       /* The class that asked for the method */
>     PyObject *im_weakreflist; /* List of weak references */
> } PyMethodObject;
>
> What was the rationale behind the "im_" prefixes on all of
> the structure's member variables?

In this case "im" is (presumably) short for Instance Method, in all cases it
makes it easy to find field references in the code base via simple search
mechanisms, and in some cases it's a helpful reminder of what kind of object
referencing code is mucking with.  Note that there are more than 5,000
instances of the identifier "self" in the C portion of the Python code base.
If you're specifically looking for uses of "self" in instance method
structs, that there are only 18 hits on im_self greatly eases the task.

the-simpler-the-conventions-the-simpler-the-needed-tools-ly y'rs  - tim





More information about the Python-list mailing list