Really stupid question regarding PEP 252 and type/class unification

Neil Schemenauer nas at python.ca
Thu Aug 23 12:05:10 EDT 2001


Terry Reedy wrote:
> 2. Think of an object's value as its (unnamed) default attribute.  IE,
> its the value you get if you do not specify a named attribute.  Note
> that this is just as true of classes and instances.

IMHO, this is the wrong way to think about it.  It's probably easier to
explain with a list rather than an integer since the current 2.2 alphas
don't yet allow subclassing integers.

    Python 2.2a1 (#12, Jul 31 2001, 10:34:28) 
    [GCC 2.95.2 20000220 (Debian GNU/Linux)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class MyList(list):
    ...   pass
    ... 
    >>> lst = MyList()
    >>> lst 
    []
    >>> 

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.

  Neil




More information about the Python-list mailing list