[Python-3000] PEP 3100 Comments

Phillip J. Eby pje at telecommunity.com
Wed May 10 18:20:26 CEST 2006


At 04:59 PM 5/10/2006 +0200, Marcin 'Qrczak' Kowalczyk <qrczak at knm.org.pl> 
wrote:
>Explicitly declared interfaces have a partial order, which is useful
>for dispatch.

Note that if the notion of "interface" is reduced to "a set of generic 
functions to which an object may be passed", then it's not necessary to 
have explicit interface declaration - it's an automatic side effect of 
implementing methods for the generic functions involved.  It also avoids 
reifying interfaces as concrete objects, except as a convenient way to 
refer to groups of generic functions.

Implementing this approach is actually a straightforward extension of 
Guido's overloaded function implementation, by replacing issubclass() with 
a generic function "implies()".  When comparing two classes, "implies()" 
would do the same as issubclass() (modulo the appropriate argument order), 
but it would also need to support comparing interface assertions with each 
other and with classes.  Overloaded functions would also need a 
"supports()" method to indicate whether the function has an unambiguous 
implementation for a given input signature.

These are very straightforward extensions -- a mild refactoring at 
most.  The only complicating factor in a production implementation would be 
that adding new methods at runtime to something like iter() would need to 
invalidate the signature caches of any generic functions with registered 
signatures based on iterability.  That means some kind of notification 
facility.  It'd be nice if it also worked for changes to a class' __bases__.


>There is little hope for inferring inclusions among
>arbitrary predicates.


It's true that inferring inclusions among truly arbitrary predicates is 
impractical, but it *can* readily be done for any N kinds of predicates, 
where N is however many you choose to implement.  RuleDispatch in fact uses 
a generic function to transform predicates into objects that can be ordered 
by inclusion, which allows applications with special needs to register new 
transformations.  (The built-in transformations change 'isinstance()' and 
'issubclass()' subexpressions into class-based criterion objects, for example.)

However, I'm not advocating that this kind of capability to be added to 
Python directly; I'd just like to be able to integrate RuleDispatch's more 
advanced features into whatever overloading machinery Python ends up with.



More information about the Python-3000 mailing list