<s> import inspect <EOL> __all__ = [ '<STR_LIT>' ] <EOL> def checkarity ( func , args , kwargs , discount = <NUM_LIT:0> ) : <EOL> '''<STR_LIT>''' <EOL> spec = inspect . getargspec ( func ) <EOL> self = getattr ( func , '<STR_LIT>' , None ) <EOL> if self and spec . args : <EOL> discount += <NUM_LIT:1> <EOL> args = list ( args ) <EOL> defaults = list ( spec . defaults or ( ) ) <EOL> len_defaults = len ( defaults ) <EOL> len_args = len ( spec . args ) - discount <EOL> len_args_input = len ( args ) <EOL> minlen = len_args - len_defaults <EOL> totlen = len_args_input + len ( kwargs ) <EOL> maxlen = len_args <EOL> if spec . varargs or spec . keywords : <EOL> maxlen = None <EOL> if not minlen : <EOL> return <EOL> if not spec . defaults and maxlen : <EOL> start = '<STR_LIT>' . format ( func . __name__ ) <EOL> else : <EOL> if maxlen and totlen > maxlen : <EOL> start = '<STR_LIT>' . format ( func . __name__ ) <EOL> else : <EOL> start = '<STR_LIT>' . format ( func . __name__ ) <EOL> if totlen < minlen : <EOL> return '<STR_LIT>' . format ( start , minlen , totlen ) <EOL> elif maxlen and totlen > maxlen : <EOL> return '<STR_LIT>' . format ( start , maxlen , totlen ) <EOL> if len_args_input < len_args : <EOL> l = minlen - len_args_input <EOL> for arg in spec . args [ discount : ] : <EOL> if args : <EOL> args . pop ( <NUM_LIT:0> ) <EOL> else : <EOL> if l > <NUM_LIT:0> : <EOL> if defaults : <EOL> defaults . pop ( <NUM_LIT:0> ) <EOL> elif arg not in kwargs : <EOL> return ( '<STR_LIT>' <EOL> . format ( func . __name__ , arg ) ) <EOL> kwargs . pop ( arg , None ) <EOL> l -= <NUM_LIT:1> <EOL> if kwargs and maxlen : <EOL> s = '<STR_LIT>' <EOL> if len ( kwargs ) > <NUM_LIT:1> : <EOL> s = '<STR_LIT:s>' <EOL> p = '<STR_LIT:U+002CU+0020>' . join ( '<STR_LIT>' . format ( p ) for p in kwargs ) <EOL> return ( '<STR_LIT>' <EOL> . format ( func . __name__ , p , s ) ) <EOL> elif len_args_input > len_args + len_defaults : <EOL> n = len_args + len_defaults <EOL> start = '<STR_LIT>' . format ( func . __name__ ) <EOL> return ( '<STR_LIT>' <EOL> . format ( start , n , len_args_input ) ) </s>
