Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle object cycles in munchify/unmunchify #41

Merged
merged 8 commits into from
Feb 28, 2019

Conversation

innermatrix
Copy link

No description provided.

test_munch.py Show resolved Hide resolved
@vmalloc
Copy link

vmalloc commented Feb 26, 2019

Thanks! I have a small request regarding the test(s), and then I'll merge your change.

@innermatrix
Copy link
Author

Good point!

I also added more tests, which resulted in me discovering that tuples were not handled correctly in some cases, which is now fixed.

The bug was that if the first object encountered in a cycle was a tuple, it would not be handled correctly. For example, although the object graph of dictX → tupleA → dictX would correctly give you munchX → tupleC → munchX, the object graph dictX → tupleA → dictY → tupleA would incorrectly give you munchX → tupleC → dictY → tupleD → dictY. Now it correctly gives munchX → tupleC → dictY → tupleC.

munch/__init__.py Outdated Show resolved Hide resolved
munch/__init__.py Outdated Show resolved Hide resolved
elif isinstance(x, list):
m.extend(cycle_munchify(v, factory, seen) for v in x)
elif isinstance(x, tuple):
for (mv, v) in zip(m, x):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please give better names to these... Too many variables spread around with single letters is very confusing to follow

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is still relevant

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be better / good now

@vmalloc
Copy link

vmalloc commented Feb 28, 2019

LGTM. Thanks for your contribution!

@vmalloc vmalloc merged commit d0fbbce into Infinidat:master Feb 28, 2019
@innermatrix
Copy link
Author

And thanks for your feedback! 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants