@@ -35,23 +35,25 @@ def _get_function_source(func):
3535 return None
3636
3737
38- def _format_args (args ):
39- """Format function arguments.
38+ def _format_args_and_kwargs (args , kwargs ):
39+ """Format function arguments and keyword arguments .
4040
4141 Special case for a single parameter: ('hello',) is formatted as ('hello').
4242 """
4343 # use reprlib to limit the length of the output
44- args_repr = reprlib .repr (args )
45- if len (args ) == 1 and args_repr .endswith (',)' ):
46- args_repr = args_repr [:- 2 ] + ')'
47- return args_repr
44+ items = []
45+ if args :
46+ items .extend (reprlib .repr (arg ) for arg in args )
47+ if kwargs :
48+ items .extend ('{}={}' .format (k , reprlib .repr (v ))
49+ for k , v in kwargs .items ())
50+ return '(' + ', ' .join (items ) + ')'
4851
4952
50- def _format_callback (func , args , suffix = '' ):
53+ def _format_callback (func , args , kwargs , suffix = '' ):
5154 if isinstance (func , functools .partial ):
52- if args is not None :
53- suffix = _format_args (args ) + suffix
54- return _format_callback (func .func , func .args , suffix )
55+ suffix = _format_args_and_kwargs (args , kwargs ) + suffix
56+ return _format_callback (func .func , func .args , func .keywords , suffix )
5557
5658 if hasattr (func , '__qualname__' ):
5759 func_repr = getattr (func , '__qualname__' )
@@ -60,14 +62,13 @@ def _format_callback(func, args, suffix=''):
6062 else :
6163 func_repr = repr (func )
6264
63- if args is not None :
64- func_repr += _format_args (args )
65+ func_repr += _format_args_and_kwargs (args , kwargs )
6566 if suffix :
6667 func_repr += suffix
6768 return func_repr
6869
6970def _format_callback_source (func , args ):
70- func_repr = _format_callback (func , args )
71+ func_repr = _format_callback (func , args , None )
7172 source = _get_function_source (func )
7273 if source :
7374 func_repr += ' at %s:%s' % source
0 commit comments