Really stupid question regarding PEP 252 and type/class unification

Alex Martelli aleax at aleax.it
Fri Aug 31 07:50:19 EDT 2001


"Russell Turpin" <russell_turpin at hotmail.com> wrote in message
news:8a12e538.0108301457.706645ef at posting.google.com...
    ...
> future data model correctly, it seems to me that "Object"
> should be made a built-in type that follows all the same
> rules as the other built-in types, distinguished primarily
> as being the default base type when no other is listed. In
> particular, I should be able to create instances without
> first sub-classing:
>
>     spam = Object()       # Create new instance

The time machine strikes again -- all this works fine
already in Python 2.2 alpha 2, except that 'object' is
spelled in lower-case:

C:\Python22>python
Python 2.2a2 (#22, Aug 22 2001, 01:24:03) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> spam = object()

>     spam.eggs = "Yes"

But *this* doesn't work, of course...:

>>> spam.eggs = "Yes"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'object' object has no attribute 'eggs'


Like those of many other built-in objects, instances of
object have no __dict__ to store arbitrary attributes in:
so, you're limited to using the predefined-slots (of which
I believe object happens to have none:-).  And you're also
underestimating the "ancestorshipness" of object...:

>>> isinstance([],object)
1
>>> isinstance("peep",object)
1
>>> isinstance(isinstance,object)
1
>>> isinstance(None,object)
1

See...?  Adam and Eve had nothing on this object guy...:-).


Alex






More information about the Python-list mailing list