[Types-sig] Interface PEP

Paul Prescod paulp@ActiveState.com
Mon, 19 Mar 2001 07:23:25 -0800


Samuele Pedroni wrote:
> 
>...
>
> On the other hand I see that we have a problem with C Extensions and
> things they produce: how do you hav defined IMatch? I imagine
> it should deal with the results of both sre and old re and isImplementedBy
> cannot do the job ;).

# should do better interfaces for these
IMatch = Interface("IMatch", "Regular expression match", 
                    lambda obj: hasattr(obj, "group"))

IRegex = Interface("IRegex", "Regular expression object",
                    lambda obj: hasattr(obj, "match"))

But note that these are of rather marginal interest. They are most often
the *return value* rather than the input of a function. The simple
checks I do above are sufficient to ensure that where they ARE used as
paramaters, you will not accidently pass one for the other or a string
for either. So the most likely mistakes are removed.

Fulton/Pelletier interfaces could make these objects more introspectable
but the simple definitions are sufficient for finding simple mistakes.

Also, it isn't quite clear to what degree they are really polymophically
replacable. I'd have to do a survey of places where they are used as
inputs to code to determine whether I should just use the concrete types
(i.e. perhaps "sre" and "pre" matches are considered incompatible) or
have an abstraction. Really, domain experts should be design the type
signatures for each module!

-- 
Take a recipe. Leave a recipe.  
Python Cookbook!  http://www.activestate.com/pythoncookbook