Preserve data type when constructing new container

Ensure that we use the original object to create the new container to
place the formatted contents into thus ensuring that we treat the
objects passed in a pure duck-typing manner rather than assuming they
are basic python data types.

Change-Id: Ib0ccea728f08ff4cf43b8ccc92477b7c46296ce9
This commit is contained in:
Darragh Bailey 2016-03-07 11:57:33 +00:00
parent 74d10e4059
commit 7782cac60e
1 changed files with 2 additions and 2 deletions

View File

@ -45,11 +45,11 @@ def deep_format(obj, paramdict, allow_empty=False):
missing_key, obj, pformat(paramdict))
raise JenkinsJobsException(desc)
elif isinstance(obj, list):
ret = []
ret = type(obj)()
for item in obj:
ret.append(deep_format(item, paramdict, allow_empty))
elif isinstance(obj, dict):
ret = {}
ret = type(obj)()
for item in obj:
try:
ret[CustomFormatter(allow_empty).format(item, **paramdict)] = \