Re: [Python-Dev] Should we do away with unbound methods in Py3k?
At 01:41 AM 11/22/2007 +0100, Amaury Forgeot d'Arc wrote:
Could we check for "real" inheritance first, and call __instancecheck__ only when the previous is false? It would speed-up the common cases.
+1.
Or is there really a use case for a derived class to appear as NOT being a subclass of its base class?
The only reason to do this would be to work around badly written code, but IMO the cure is worse than the disease at that point. The lookup sequence should probably be something like: 1. type(ob) is cls 2. issubclass(type(ob), cls) 3. ob.__class__ is cls 4. issubclass(ob.__class__, cls) 5. ob.__instancecheck__(cls) Where issubclass() checks __mro__ before calling the subclass check method, and #3 and #4 can be skipped if ob.__class__ is type(ob).
Phillip J. Eby wrote:
The lookup sequence should probably be something like:
1. type(ob) is cls 2. issubclass(type(ob), cls)
But can't issubclass be overridden as well? -- Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | greg.ewing@canterbury.ac.nz +--------------------------------------+
At 03:48 PM 11/22/2007 +1300, Greg Ewing wrote:
Phillip J. Eby wrote:
The lookup sequence should probably be something like:
1. type(ob) is cls 2. issubclass(type(ob), cls)
But can't issubclass be overridden as well?
Yes, which is why I spelled it that way, and mentioned that 'issubclass()' should check class identity and __mro__ before falling through to the special method check.
participants (2)
-
Greg Ewing
-
Phillip J. Eby