I've come across answers here for type checking in general, type checking for numbers, and type checking for strings. Most people seem to respond by saying that type checking should never be performed in python (< 2.6) due to duck typing. My (limited) understanding of duck typing is that type is determined by use of an object's attributes. What do I do if I'm not using any attributes?
I have a simple function that determines constants based on the argument, which should be a number. I raise an exception defined by
class outOfBoundsError(ValueError):
"""
Specified value is outside the domain.
"""
with a message telling them the number they gave me is too big. I would like to keep this message specific. But if the argument is a string (like 'charlie'
), it still considers the argument to be greater than my specified number (and raises my exception). Should I just add a dummy line to the code like argument + 2
so that a TypeError is raised?
Note: I don't know anything about ABCs but I don't think they're available to me since the latest python version we have access to is 2.5 : (.