[Python-Dev] Should we do away with unbound methods in Py3k?

Phillip J. Eby pje at telecommunity.com
Thu Nov 22 01:53:22 CET 2007


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).



More information about the Python-Dev mailing list