Merge "Modify flatten method to display an empty dict"

This commit is contained in:
Jenkins
2016-08-05 00:28:19 +00:00
committed by Gerrit Code Review
2 changed files with 5 additions and 3 deletions

View File

@@ -340,7 +340,8 @@ class FlattenTestCase(test_utils.TestCase):
'b4': {'c1': ['l', 'l', ['l']],
'c2': 'string'}},
'a2': ['l'],
'a3': ('t',)})
'a3': ('t',),
'a4': {}})
self.assertEqual({'a1_b1': 1234,
'a1_b2': 'string',
@@ -348,7 +349,8 @@ class FlattenTestCase(test_utils.TestCase):
'a1_b4_c1': ['l', 'l', ['l']],
'a1_b4_c2': 'string',
'a2': ['l'],
'a3': ('t',)},
'a3': ('t',),
'a4': {}},
squashed)
def test_pretty_choice_dict(self):

View File

@@ -210,7 +210,7 @@ def _flatten(data, prefix=None):
if isinstance(data, dict):
for key, value in six.iteritems(data):
new_key = '%s_%s' % (prefix, key) if prefix else key
if isinstance(value, (dict, list)):
if isinstance(value, (dict, list)) and value:
for item in _flatten(value, new_key):
yield item
else: