From c3324fc7e4bce6facce5d90d5bae02f8bbd724b9 Mon Sep 17 00:00:00 2001 From: Alexey Stepanov Date: Tue, 11 Oct 2016 16:36:03 +0300 Subject: [PATCH] Renamed *args, **kwargs: bind correctly on Py2.7 Use search and inject Copied from the fuel-devops 3.0.3 Change-Id: Ibd454eb22b7bc534e790212cd536e553eed74ca8 --- core/helpers/log_helpers.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/helpers/log_helpers.py b/core/helpers/log_helpers.py index f6bfb1fe4..829d8181d 100644 --- a/core/helpers/log_helpers.py +++ b/core/helpers/log_helpers.py @@ -68,10 +68,21 @@ def _getcallargs(func, *positional, **named): if six.PY2: # args and kwargs is not bound in py27 # Note: py27 inspect is not unicode - if 'args' in orig_args: - arguments[b'args'] = orig_args['args'] - if 'kwargs' in orig_args: - arguments[b'kwargs'] = orig_args['kwargs'] + missed = ( + (key, val) + for key, val in orig_args.items() + if key not in arguments) + args, kwargs = (), () + for record in missed: + if isinstance(record[1], (list, tuple)): + args = record + elif isinstance(record[1], dict): + kwargs = record + + if args: + arguments[args[0]] = args[1] + if kwargs: + arguments[kwargs[0]] = kwargs[1] return arguments sig = inspect.signature(func).bind(*positional, **named) sig.apply_defaults() # after bind we doesn't have defaults