On 2005 Jan 12, at 16:45, Guido van Rossum wrote:

My personal POV here: even when you break Liskov in subtle ways, there
are lots of situations where assuming substitutability has no ill
effects, so I'm happy to pretend that a subclass is always a subtype
of all of its base classes, (and their base classes, etc.). If it
isn't, you can always provide an explicit adapter to rectify things.

Ah, this is the crucial point: an explicit adapter must take precedence over substitutability that is assumed by subclassing. From my POV this does just as well as any other kind of explicit control about whether subclassing implies substitutability.


In retrospect, that's the same strategy as in copy.py: *FIRST*, check the registry -- if something is found in the registry, THAT takes precedence. *THEN*, only for cases where the registry doesn't give an answer, proceed with other steps and checks and sub-strategies.

So, I think PEP 246 should specify that the step now called (e) [checking the registry] comes FIRST; then, an isinstance step [currently split between (a) and (d)], then __conform__ and __adapt__ steps [currently called (b) and (c)]. Checking the registry is after all very fast: make the 2-tuple (type(obj), protocol), use it to index into the registry -- period. So, it's probably not worth complicating the semantics at all just to "fast path" the common case.

I intend to restructure pep246 at next rewrite to reflect this "obvious once thought of" idea, and thanks, Guido, for providing it.


Alex

_______________________________________________
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