birthday typeerrorargument not in running python with its - flag at system command line will disable range testingbut also avoid the performance overhead of the wrapping layer--we wind up calling the original undecorated function directly assuming this is debugging tool onlyyou can use this flag to optimize your program for production usec:\codepython - rangetest _test py false bob smith is years old birthday generalizing for keywords and defaultstoo the prior version illustrates the basics we need to employbut it' fairly limited--it supports validating arguments passed by position onlyand it does not validate keyword arguments (in factit assumes that no keywords are passed in way that makes argument position numbers incorrectadditionallyit does nothing about arguments with defaults that may be omitted in given call that' fine if all your arguments are passed by position and never defaultedbut less than ideal in general tool python supports much more flexible argument-passing modeswhich we're not yet addressing the mutation of our example shown next does better by matching the wrapped function' expected arguments against the actual arguments passed in callit supports range validations for arguments passed by either position or keyword nameand it skips testing for default arguments omitted in the call in shortarguments to be validated are specified by keyword arguments to the decoratorwhich later steps through both the *pargs positionals tuple and the **kargs keywords dictionary to validate ""file rangetest pyfunction decorator that performs range-test validation for arguments passed to any function or method arguments are specified by keyword to the decorator in the actual callarguments may be passed by position or keywordand defaults may be omitted see rangetest_test py for example use cases ""trace true def rangetest(**argchecks)validate ranges for both+defaults def ondecorator(func)oncall remembers func and argchecks if not __debug__true if "python - main py args return func wrap if debuggingelse use original elsecode func __code__ allargs code co_varnames[:code co_argcountfuncname func __name__ examplevalidating function arguments