Format function arguments and keyword arguments. Special case for a single parameter: ('hello',) is formatted as ('hello'). Note that this function only returns argument details when debug=True is specified, as arguments may contain sensitive information.
(args, kwargs, *, debug=False)
| 28 | |
| 29 | |
| 30 | def _format_args_and_kwargs(args, kwargs, *, debug=False): |
| 31 | """Format function arguments and keyword arguments. |
| 32 | |
| 33 | 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. |
| 38 | """ |
| 39 | if not debug: |
| 40 | return '()' |
| 41 | |
| 42 | # use reprlib to limit the length of the output |
| 43 | items = [] |
| 44 | if args: |
| 45 | items.extend(reprlib.repr(arg) for arg in args) |
| 46 | if kwargs: |
| 47 | items.extend(f'{k}={reprlib.repr(v)}' for k, v in kwargs.items()) |
| 48 | return '({})'.format(', '.join(items)) |
| 49 | |
| 50 | |
| 51 | def _format_callback(func, args, kwargs, *, debug=False, suffix=''): |