Type Hinting vs Type Checking and Preconditions

Jay Parlar jparlar at cogeco.ca
Wed Mar 8 14:52:15 EST 2006


On Mar 8, 2006, at 8:43 AM, Tom Bradford wrote:
>
>
> This type of hinting would only break type ducking in-so-much as a
> function that leveraged that hinting would be looking specifically for
> an instance of a particular type, which would be absolutely no
> different than a developer performing the type check manually and
> throwing it out if the type were invalid.  It would otherwise just be a
> lot of tedious and repetitive work for the developer.
>

Wow, I *really* hope that you're not writing functions that check the 
types of the incoming arguments. It's generally accepted that using 
"isinstance()" and "type()" in your code are evil things to do. There 
are very few places where it's appropriate to use them.

If you're using them a lot, then I suspect you're relatively new to 
Python, and are programming with a Java/C++ mindset. We'll have to do 
what we can to get you out of that :)

Jay P.




More information about the Python-list mailing list