Mar-06-2018, 07:40 AM
(This post was last modified: Mar-06-2018, 11:31 AM by Gribouillis.)
Function arguments are seldom checked in python, but there is a place where they are often checked: the standard library! (at least the functions implemented in C). So we cannot say that this is fundamentally unpythonic. It depends on the use case. I would check what the values should be rather than what they should not be, so for example, with more explicit name and message
from numbers import Number def _fail_unless_non_negative_number(*kwargs): for k, v in kwargs.items(): if not (isinstance(v, Number) and (v >= 0)): raise TypeError(('Expected non negative number for parameter', k, 'got', repr(v)))