Top-rated recipes tagged "typecheck" Code RecipesDecorator to check method param types (Python) 2014-01-14T11:23:40-08:00Andrey Nikishaev <p style="color: grey"> Python recipe 578809 by <a href="/recipes/users/4176176/">Andrey Nikishaev</a> (<a href="/recipes/tags/decorators/">decorators</a>, <a href="/recipes/tags/method/">method</a>, <a href="/recipes/tags/typecheck/">typecheck</a>). </p> <p>This solution give possibility to check method param type, raise needed exception type, and also have good readability in the decorator definition.</p> Type checking using Python 3.x annotations (Python) 2013-05-23T22:46:19-07:00David Mertz <p style="color: grey"> Python recipe 578528 by <a href="/recipes/users/4173018/">David Mertz</a> (<a href="/recipes/tags/annotations/">annotations</a>, <a href="/recipes/tags/check/">check</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/type/">type</a>, <a href="/recipes/tags/typecheck/">typecheck</a>). Revision 5. </p> <p>Some other recipes have been suggested to allow type checking by various means. Some of these require the use of type specification in a decorator itself. Others try to be much more elaborate in processing a large variety of annotations (but hence require much more and more convoluted code).</p> <p>The recipe provided below is very short, and simply provides actual <strong>type</strong> checking of arguments and return values. It utilizes an unadorned decorator, rather than manufacture one that is parameterized by types or other arguments.</p>