[Python-bugs-list] [ python-Bugs-532767 ] isinstance() should respect __class__

noreply@sourceforge.net noreply@sourceforge.net
Thu, 21 Mar 2002 05:16:17 -0800


Bugs item #532767, was opened at 2002-03-20 17:22
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=532767&group_id=5470

Category: Type/class unification
>Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Steve Alexander (stevea_zope)
Assigned to: Guido van Rossum (gvanrossum)
Summary: isinstance() should respect __class__

Initial Comment:
isinstance(obj, class_or_type_or_tuple) should compare
using obj.__class__ when obj is an instance of a type
or a new-style class.

This is important for using weak references and other
kinds of proxy wrappers, where you want to pass a proxy
to some code, which might query its type using isinstance.

issubclass may need a similar treatment.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-03-21 08:16

Message:
Logged In: YES 
user_id=6380

I give this a +1. To refute Martin's -1: The use case that
prompts this is passing a wrapper to wrapper-ignorant code.
This may be 3rd party code that you can't afford to make
wrapper-aware. If I pass you a wrapper to an X where you
expect an X, your isinstance(x, X) call should succeed.
Especially since x.__class__ already returns X. Also,
isinstance(x, X) succeeds if X is a classic class and x is a
wrapped X instance.

If you want to know if something is a wrapper, you have to
use type().

----------------------------------------------------------------------

Comment By: Martin v. Löwis (loewis)
Date: 2002-03-21 03:59

Message:
Logged In: YES 
user_id=21627

-1. That means that you can't use isinstance anymore to
determine whether something is a weak reference, or other
kind of proxy wrapper.

If you need a function that unwraps wrappers, write one
yourself.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=532767&group_id=5470