Python
recipe 578528
by David Mertz
(annotations, check, decorator, python3, type, typecheck).
Revision 5.
Some other recipes have been suggested to allow type checking by various means. Some of these require the use of type s...
Python
recipe 578528
by David Mertz
(annotations, check, decorator, python3, type, typecheck).
Revision 5.
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).
The recipe provided below is very short, and simply provides actual type checking of arguments and return values. It utilizes an unadorned decorator, rather than manufacture one that is parameterized by types or other arguments.