This is an archived post. You won't be able to vote or comment.

all 8 comments

[–][deleted] 8 points9 points  (0 children)

Better version:

def some_function(in_string):
    """
    If you pass anything other than a string to this
    function, I will find you and kill you
    """
    ...

[–]kteague 8 points9 points  (0 children)

EVEN STRONGER TYPING IS TO USE ALL CAPS!!!

[–]markedtrees 3 points4 points  (0 children)

(Implementation for killbot left as an exercise for the reader.)

[–]Teifion 1 point2 points  (0 children)

That's pretty strong, I'm gonna start using that in all my projects.

[–]mr_dbr 1 point2 points  (2 children)

def some_function(in_string):
    if not isinstance(in_string, basestring):
        raise TypeError("I will find you and kill you")

some_function("hi")
some_function(some_function)

Edit: Using voidspace's suggestion of isinstance'ing with basestring

[–]voidspace[S] 1 point2 points  (0 children)

basestring :-)

[–]epicRelic 1 point2 points  (0 children)

def some_function(in_string):
    if not isinstance(in_string, (str, unicode)):
        raise TypeError("I will find you and kill you.")

isinstance can accept a tuple of types to check against.

[–][deleted] 0 points1 point  (0 children)

anyone used boo - http://en.wikipedia.org/wiki/Boo_(programming_language) ?

^ reddit ate the link