[Python-Dev] Updated Monkey Typing pre-PEP

Mark Russell marktrussell at btopenworld.com
Thu Jan 20 13:33:05 CET 2005


On Thu, 2005-01-20 at 11:07, Guido van Rossum wrote:
> I'd also like to explore ways of creating partial interfaces on the
> fly. For example, if we need only the read() and readlines() methods
> of the file protocol, maybe we could declare that as follows::
> 
>   def foo(f: file['read', 'readlines']): ...
> 
> I find the quoting inelegant, so maybe this would be better::
> 
>   file[file.read, file.readlines]

Could you not just have a builtin which constructs an interface on the
fly, so you could write:

    def foo(f: interface(file.read, file.readlines)): ...

For commonly used subsets of course you'd do something like:

    IInputStream = interface(file.read, file.readlines)

    def foo(f: IInputStream): ...

I can't see that interface() would need much magic - I would guess you
could implement it in python with ordinary introspection.

Mark Russell



More information about the Python-Dev mailing list