Raising objects

Steven Taschuk staschuk at telusplanet.net
Fri May 2 17:25:43 EDT 2003


Quoth Aahz:
  [...]
> Yes, you're missing the focus on instances.  Currently, when you raise
> an object, it gets accepted as-is if it's an instance, but instantiated
> if it's a class.  How do you tell whether something is an instance?

For new-style objects, it's an instance if it's not a type, i.e. if
    isinstance(x, type)
is false.

    >>> class Cls(object):
    ...     pass
    ... 
    >>> isinstance(Cls, type)
    1
    >>> isinstance(Cls(), type)
    0

To accommodate old-style classes too:
    isinstance(x, type) or isinstance(x, types.ClassType)
is true when x is a class or type, false when x is an instance.

(I speak here as if instances and types are disjoint categories,
and of course they are not.  All types are also instances, namely
instances of their metaclass.  But for the purposes of implicit
instantiation during raising, I think this can be safely ignored.
Moreover, I want implicit instantiation to go away eventually
anyway, so the distinction only has to be good enough to support a
backwards compatibility hack, not any putative One True
Distinction between instances and types.)

-- 
Steven Taschuk                                7\ 7'Z {&~         .
staschuk at telusplanet.net                        Y r          --/hG-
                                            (__/ )_             1^1`





More information about the Python-list mailing list