[Python-ideas] Improving the expressivity of function annotations

Masklinn masklinn at masklinn.net
Mon Apr 4 10:49:32 CEST 2011


On 2011-04-04, at 10:44 , Carl M. Johnson wrote:
> It wouldn't be that hard to make a class decorator that would work like:
> 
> @interface
> class Duck:
>    def quack(): pass
>    def walk(): pass
> 
> class Mallard:
>   def quack():
>       print("quack")
>   def walk():
>       print("waddle")
> 
> assert issubclass(Mallard, Duck) #Passes.
> 
> Where "interface" is a loose term like Go, and anything with the
> relevant methods counts as a subclass. It would probably make sense to
> add something like that to the abc module.

The "issue" is roughly the same as for abcs, in that you still have to give a name (and pre-define a type) for something which may not warrant it, and this naming may even serve to muddy the water some cases when used in type signatures (see Mapping abc example)

Otherwise, sure.


More information about the Python-ideas mailing list