[Python-Dev] Should we do away with unbound methods in Py3k? (original) (raw)

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