Type checking in python?

matt at nightrealms.com.bbs matt at nightrealms.com.bbs
Mon Jul 17 16:50:04 EDT 2000


In article <397296BC.415C97E1 at prescod.net>, Paul Prescod
<paul at prescod.net> wrote:

> Matthew Cline wrote:
>>
>>   def my_func(foo, bar, quux):
>>      if not isinstance(quux, Quux):
>>         raise RuntimeError("param 'quux' must be of class 'Quux'")
>
> Let me also point out that in many cases, this style of programming
> would be frowned upon by serious Python programmers. For instance,
> if you check that something is a string, your code will complain
> when it is handed a Unicode string, even though it would probably
> work fine. If you check that it is an open file, then your code
> probably will complain about stringIO file-like objects, even though
> it would probably work fine.

That's another reason why I'd like the type checking to be done by the
Python compiler, because it could be intelligent about those things.
Like for "list" it could accept a tuple, a list, or anything derived
from UserList.



More information about the Python-list mailing list