Last active
December 10, 2015 08:38
-
-
Save domenkozar/4409304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import collections | |
def nest_variables(variables): | |
nested = dict() | |
for key, value in variables.items(): | |
segments = key.split('.') | |
location = nested | |
for segment in segments[:-1]: | |
if segment not in location: | |
location[segment] = dict() | |
location = location[segment] | |
print("location: %s" % location) | |
print("nested: %s" % nested) | |
if not isinstance(location, dict): | |
print('good') | |
return | |
location[segments[-1]] = value | |
print('bad') | |
# use ordereddict, just to be sure order is irrelevant | |
nest_variables(collections.OrderedDict({'foo.bar': '1', 'foo': '2'})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
Seems to be the case of two bugs. One being introduction of hash randomization (or better say dict really not keeping the order) and the other of test case not covering a bug, which I was hunting.
Bottom of line, this fails due to careless passing of dict instead of ordereddict.