[docs]defis_function(f:object,arg_count:int,coroutine:bool=False)->bool:""" Check and require a function that can accept the specified number of positional arguments, which either is or is not a coroutine type casting "functions" are allowed, but only in the 1-argument form. Args: f: Function to check. arg_count: Number of argument f should accept. coroutine: Is a coroutine. Return: bool: is function and accepts the specified number of arguments. """ifnotisinstance(arg_count,int)orarg_count<0:raiseTypeError("arg_count must be a non-negative integer")ifnot(callable(f)andbool(coroutine)isiscoroutinefunction(f)):returnFalseifisinstance(f,type):# for type casting functions, eg int, str, float# only support the one-parameter form of these,# otherwise the user should make an explicit function.returnarg_count==1try:sig=signature(f)exceptValueError:# some built-in functions/methods don't describe themselves to inspect# we already know it's a callable and coroutine is correct.returnTruetry:inputs=[0]*arg_countsig.bind(*inputs)returnTrueexceptTypeError:returnFalse