duck-type-checking?

Joe Strout joe at strout.net
Wed Nov 12 21:17:39 CET 2008


On Nov 12, 2008, at 11:48 AM, pruebauno at latinmail.com wrote:

> It seems to me that what you are describing is exactly what abcs were
> added for in 2.6, in particular registration:
>
> class AnotherClass(metaclass=ABCMeta):
>    pass
> AnotherClass.register(basestring)
>
> assert isinstance(str, AnotherClass)
>
> Please read this first:
> http://www.python.org/dev/peps/pep-3119/
>
> and tell us why that would not work.

You're right, that is exactly the need I was looking to fill.  Thanks  
for pointing it out!

Now I have only two regrets: first, that our shop is still using 2.5  
and this functionality is new in 2.6; and second, that it does not  
appear to include an easy way to check the types of elements of a  
sequence or mapping.

Still, I can see that this is a very carefully considered PEP and is  
the best solution for the future, so I will study it carefully and  
incorporate it into our practices ASAP.

Thanks,
- Joe




More information about the Python-list mailing list