[Python-3000] my take on "typeclasses"

Oleg Broytmann phd at mail2.phd.pp.ru
Tue May 9 22:57:48 CEST 2006


On Tue, May 09, 2006 at 10:31:02PM +0200, tomer filiba wrote:
> i.e., "is the object addable?" == "hasattr(obj, '__add__')".

   Even this is meaningless: '1'+1. So duck typing is:

try:
   return a+b
except TypeError:
   return "Oops..."

> iterable_protocol = ["__iter__"]
> sequence_protocol = ["__getitem__", "__setitem__",
> "__contains__", "__iter__"]

   A read-only sequence could lack __setitem__().

> file_protocol = ["write", "read", "close", "fileno"]

   StringIO lacks fileno() so it is not a file-like object, is it?

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-3000 mailing list