Skip to content

Commit 04bea0a

Browse files
authored
Simplify logic in varmap (#1594)
1 parent 79b58ce commit 04bea0a

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

‎elasticapm/utils/__init__.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,15 @@ def varmap(func, var, context=None, name=None, **kwargs):
6363
if objid in context:
6464
return func(name, "<...>", **kwargs)
6565
context.add(objid)
66-
if isinstance(var, dict):
67-
# Apply func() before recursion, so that `shorten()` doesn't have to iterate over all the trimmed values
68-
ret = func(name, var, **kwargs)
66+
67+
# Apply func() before recursion, so that `shorten()` doesn't have to iterate over all the trimmed values
68+
ret = func(name, var, **kwargs)
69+
if isinstance(ret, dict):
6970
# iterate over a copy of the dictionary to avoid "dictionary changed size during iteration" issues
7071
ret = dict((k, varmap(func, v, context, k, **kwargs)) for k, v in ret.copy().items())
71-
elif isinstance(var, (list, tuple)):
72+
elif isinstance(ret, (list, tuple)):
7273
# Apply func() before recursion, so that `shorten()` doesn't have to iterate over all the trimmed values
73-
ret = func(name, var, **kwargs)
7474
ret = [varmap(func, f, context, name, **kwargs) for f in ret]
75-
else:
76-
ret = func(name, var, **kwargs)
7775
context.remove(objid)
7876
return ret
7977

0 commit comments

Comments
 (0)