@@ -19,19 +19,26 @@ def _get_function_source(func):
1919 return None
2020
2121
22- def _format_callback_source (func , args ):
23- func_repr = _format_callback (func , args , None )
22+ def _format_callback_source (func , args , * , debug = False ):
23+ func_repr = _format_callback (func , args , None , debug = debug )
2424 source = _get_function_source (func )
2525 if source :
2626 func_repr += f' at { source [0 ]} :{ source [1 ]} '
2727 return func_repr
2828
2929
30- def _format_args_and_kwargs (args , kwargs ):
30+ def _format_args_and_kwargs (args , kwargs , * , debug = False ):
3131 """Format function arguments and keyword arguments.
3232
3333 Special case for a single parameter: ('hello',) is formatted as ('hello').
34+
35+ Note that this function only returns argument details when
36+ debug=True is specified, as arguments may contain sensitive
37+ information.
3438 """
39+ if not debug :
40+ return '()'
41+
3542 # use reprlib to limit the length of the output
3643 items = []
3744 if args :
@@ -41,10 +48,11 @@ def _format_args_and_kwargs(args, kwargs):
4148 return '({})' .format (', ' .join (items ))
4249
4350
44- def _format_callback (func , args , kwargs , suffix = '' ):
51+ def _format_callback (func , args , kwargs , * , debug = False , suffix = '' ):
4552 if isinstance (func , functools .partial ):
46- suffix = _format_args_and_kwargs (args , kwargs ) + suffix
47- return _format_callback (func .func , func .args , func .keywords , suffix )
53+ suffix = _format_args_and_kwargs (args , kwargs , debug = debug ) + suffix
54+ return _format_callback (func .func , func .args , func .keywords ,
55+ debug = debug , suffix = suffix )
4856
4957 if hasattr (func , '__qualname__' ) and func .__qualname__ :
5058 func_repr = func .__qualname__
@@ -53,7 +61,7 @@ def _format_callback(func, args, kwargs, suffix=''):
5361 else :
5462 func_repr = repr (func )
5563
56- func_repr += _format_args_and_kwargs (args , kwargs )
64+ func_repr += _format_args_and_kwargs (args , kwargs , debug = debug )
5765 if suffix :
5866 func_repr += suffix
5967 return func_repr
0 commit comments