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

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to