Skip to content

Commit

Permalink
Merge pull request #77 from trailofbits/76-fix-pydiff-build-tree
Browse files Browse the repository at this point in the history
Fixes a bug in building Python object diffs
  • Loading branch information
ESultanik authored Aug 8, 2023
2 parents 96df7f9 + e2b65b2 commit f205f21
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
{% endfor %}
{% else %}
<dd><a href="/graphtage/latest">latest</a></dd>
<dd><a href="/graphtage/v0.3.0">0.3.0</a></dd>
<dd><a href="/graphtage/v0.2.9">0.2.9</a></dd>
<dd><a href="/graphtage/v0.2.8">0.2.8</a></dd>
<dd><a href="/graphtage/v0.2.7">0.2.7</a></dd>
Expand Down
4 changes: 2 additions & 2 deletions graphtage/pydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ def __init__(self, key, value):
stack.append((obj, [], [obj.value]))
elif isinstance(obj, dict):
stack.append(({}, [], [DictValue(key=k, value=v) for k, v in reversed(list(obj.items()))]))
elif isinstance(python_obj, (list, tuple)):
elif isinstance(obj, (list, tuple)):
stack.append(([], [], list(reversed(obj))))
elif python_obj is None:
elif obj is None:
new_node = NullNode()
else:
pyobj = PyObj(class_name=StringNode(obj.__class__.__name__, quoted=False), attrs=None) # type: ignore
Expand Down
2 changes: 1 addition & 1 deletion graphtage/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def git_branch() -> Optional[str]:
"""


__version__: Tuple[Union[int, str], ...] = (0, 2, 9)
__version__: Tuple[Union[int, str], ...] = (0, 3, 0)

if DEV_BUILD:
branch_name = git_branch()
Expand Down
10 changes: 10 additions & 0 deletions test/test_pydiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ def __init__(self, bar, baz):

printer = graphtage.printer.Printer(ansi_color=True)
print_diff(Foo("bar", "baz"), Foo("bar", "bak"), printer=printer)

def test_nested_tuple_diff(self):
tree = build_tree({"a": (1, 2)})
self.assertIsInstance(tree, graphtage.DictNode)
children = tree.children()
self.assertEqual(1, len(children))
kvp = children[0]
self.assertIsInstance(kvp, graphtage.KeyValuePairNode)
self.assertIsInstance(kvp.key, graphtage.StringNode)
self.assertIsInstance(kvp.value, graphtage.ListNode)

0 comments on commit f205f21

Please sign in to comment.