Type checking

Christopher T King squirrel at WPI.EDU
Thu Jul 1 09:03:02 EDT 2004


George Sakkis wrote:

> I wonder if people have come up with such pitfalls in practice or I was just
> careless. In any case, I was tempted enough to write a simple extensible
> runtime type checking module, which can be handy, at least during
> development. It's extensible in the sense that a "type" can be any

And in other places: some functions need to behave differently depending 
on the types of their arguments. When interfaces come into play, 
isinstance() just doesn't cut it.

> ContainerOf, TupleOf, ListOf and DictOf are all extensions of the abstract
> TypeChecker class, providing some limited but common templated-type
> checking. Of course in practice most complex structures (e.g. phonebook)
> would be encapsulated in a class, so it's questionable whether such
> functionality adds up anything to a list of "assert isinstance(object,type)"
> statements. Any ideas or suggestions are welcome.

Along with TupleOf, ListOf, DictOf, etc., include interface checkers, 
such as SequenceOf and MappingOf. People will love you for it.




More information about the Python-list mailing list