type() for new style classes - buggy?

Skip Montanaro skip at pobox.com
Wed Jan 28 16:11:03 CET 2004


    Michal>  does the type() command work correctly for new style classes?

Yes.  Using 2.2:

    >>> class A(object): pass
    ... 
    >>> type(A)
    <type 'type'>
    >>> type(A())
    <class '__main__.A'>
    >>> isinstance(A(), A)
    1

Using 2.3 or newer:

    >>> class A(object):
    ...   pass
    ... 
    >>> type(A)
    <type 'type'>
    >>> type(A())
    <class '__main__.A'>
    >>> isinstance(A(), A)
    True

In general, you shouldn't be using the types module, certainly not for
new-style classes.

Skip




More information about the Python-list mailing list