Is 'isinstance()' the right thing?

Alex Martelli aleax at aleax.it
Tue Apr 30 04:58:07 EDT 2002


Ralf Juengling wrote:

> when I want to make sure within a function that it can deal with
> the arguments passed, the only choice is to check it's type via
> 'isinstance()'. However, in general the type of an argument is
> not the crux but whether the argument supports a certain
> 'interface' or 'protocol'. Thus, a function 'hasinterface()'
> would appear more natural (more 'Pythonic') to me.
> 
> So, what is the proper, 'pythonic' way of argument checking?

PEP 246, but I haven't yet been able to communicate the how's
and why's of it to the BDFL.

Meanwhile, http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52291
may help.


Alex




More information about the Python-list mailing list