Really stupid question regarding PEP 252 and type/class unification
Terry Reedy
tjreedy at home.com
Fri Aug 24 01:19:21 EDT 2001
"Russell Turpin" <russell_turpin at hotmail.com> wrote in message
news:8a12e538.0108231711.49d74a5a at posting.google.com...
> Neil Schemenauer <nas at python.ca> wrote in message
news:<mailman.998582617.17836.python-list at python.org>...
> > The object "lst" does not have some hidden attribute that
> > is a list. It really is itself a list object. That's the
> > way things are implemented. Using some other mental model
> > is bound to get you into trouble sooner or later.
>
> This gets to the nub of the matter. Let's take your example:
>
> class MyList(list):
> pass
>
> lst = MyList()
>
> So "lst" is really a list. But it also is really an object,
*Everying in Python is an object, including all builtins.
> instantiated from a class.
Currently it would be better to think of it as instantiated from a
subtype. The type of a class instance is 'instance'. The type of a
subtype instance is that subtype, just as the type of a list instance
is 'list'.
> So one can do things like:
>
> lst.a = "I just created attribute 'a'."
> lst.b = []
>
> This is correct, right?
According to what I understood from some emails from Guido, the
internal difference between a list instance and a mylist instance is
the addition to the structure of a pointer to __dict__, which allows
user-defined attributes. Otherwise, the layout is *exactly* the same
(and different from an 'instance' object).
Terry J. Reedy
More information about the Python-list
mailing list