[Python-Dev] PEP 246, redux
Alex Martelli
aleax at aleax.it
Wed Jan 12 17:02:11 CET 2005
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
More information about the Python-Dev
mailing list