From bed9b0a56c92afbd7747f3b0c57d888ead761f6e Mon Sep 17 00:00:00 2001 From: 1cbyc Date: Wed, 9 Sep 2026 13:38:29 +0000 Subject: [PATCH] Fix quoted Python attribute receivers Co-authored-by: insisong --- graphtage/pydiff.py | 4 ++-- test/test_pydiff.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/graphtage/pydiff.py b/graphtage/pydiff.py index a68313c..ac4c358 100644 --- a/graphtage/pydiff.py +++ b/graphtage/pydiff.py @@ -61,8 +61,8 @@ class PyObjAttribute(DataClassNode): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - if isinstance(object, StringNode): - object.quoted = False + if isinstance(self.object, StringNode): + self.object.quoted = False self.attr.quoted = False diff --git a/test/test_pydiff.py b/test/test_pydiff.py index ed70fd8..7b36b8c 100644 --- a/test/test_pydiff.py +++ b/test/test_pydiff.py @@ -1,9 +1,10 @@ import ast import dataclasses +from io import StringIO from unittest import TestCase import graphtage -from graphtage.pydiff import PyDiffFormatter, ast_to_tree, build_tree, print_diff +from graphtage.pydiff import PyDiffFormatter, PyObjAttribute, ast_to_tree, build_tree, print_diff from .timing import run_with_time_limit @@ -22,6 +23,17 @@ def test_python_list_literals_stay_ordered(self): for node in tree.dfs(): self.assertNotIsInstance(node, graphtage.UnorderedListNode) + def test_attribute_receiver_is_not_quoted(self): + stream = StringIO() + attribute = PyObjAttribute(graphtage.StringNode("package"), graphtage.StringNode("member")) + + PyDiffFormatter.DEFAULT_INSTANCE.print( + graphtage.Printer(out_stream=stream, ansi_color=False), + attribute, + ) + + self.assertEqual("package.member", stream.getvalue()) + def test_diff(self): t1 = [1, 2, {3: "three"}, 4] t2 = [1, 2, {3: 3}, "four"]