Python simple type checking decorator
To amplify @200_success’s comment:

Python 3.5 introduces type hints.  Eg)

&gt;&gt;&gt; def foo2(x:str, y:float) -&gt; None:
...    print(f"Hi, foo has been called with {x} {y}")
... 
&gt;&gt;&gt; foo2("2", 3.4)
Hi, foo has been called with 2 3.4
&gt;&gt;&gt;


These type hints (the x:str, and y:float) are not used by the standard Python interpreter, but they are recorded during the parsing of the code, so they are available to the program.

&gt;&gt;&gt; foo2.__annotations__
{'return': None, 'x': &lt;class 'str'&gt;, 'y': &lt;class 'float'&gt;}
&gt;&gt;&gt; 


Directly accessing the foo2.__annotations__ is not that interesting, but accessing func.__annotations__ in the @typecheck decorator means you don’t have to provide the argument types to the decorator; the decorator can inspect the argument types directly.  Thus you could decorate the function with simply @typecheck, instead of @typecheck(str, float).

For a variant str or float type argument, you could use the typing module to define your own STR_OR_FLOAT = TypeVar("STR_OR_FLOAT", str, float) type (or a better name if you have one), which you could decorate the argument with.

As a bonus, using type hints to provide argument type checking information — even for your do-it-yourself via a function decorator type check system — also gives you the following benefits:


IDE type hints, as you are writing code
Can be understood by standard documentation generators
Only consumes CPU time during parsing of the code; does not affect execution speed