[ python-Bugs-1263635 ] type() and isinstance() do not call __getattribute__

SourceForge.net noreply at sourceforge.net
Fri Aug 26 10:48:44 CEST 2005


Bugs item #1263635, was opened at 2005-08-18 21:07
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1263635&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Per Vognsen (pervognsen)
Assigned to: Nobody/Anonymous (nobody)
Summary: type() and isinstance() do not call __getattribute__

Initial Comment:
The built-in functions type() and isinstance() do not call 
__getattribute__ for instances of user-defined classes. 
Thus, for instance,

x.__class__ == sometype

and

type(x) == sometype

can give inconsistent results.

I ran into this problem in writing a transparent 
persistence system, where instances of proxy classes 
are used as stand-ins for unloaded objects and the 
proxy does just-in-time loading by overloading 
__getattribute__ and __setattr__ (which changes 
__class__).

(This applies to 2.4.1.)

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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2005-08-26 03:48

Message:
Logged In: YES 
user_id=80475

I don't think this is going to change.  A number of builtins
directly access an object's structure and do not respect
overrides via __getattribute__.  This is somewhat intrinsic
the Python's current design.

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

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


More information about the Python-bugs-list mailing list