diff --git a/tests/test_items.py b/tests/test_items.py index 82f2820..9da84b7 100644 --- a/tests/test_items.py +++ b/tests/test_items.py @@ -308,6 +308,7 @@ def test_array_behaves_like_a_list(): content = """a = [1, 2,] # Comment """ doc = parse(content) + assert str(doc) == "{'a': [1, 2]}" assert str(doc["a"]) == "[1, 2]" assert doc["a"] == [1, 2] diff --git a/tomlkit/items.py b/tomlkit/items.py index b80e9f1..1c6ef8d 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -573,6 +573,12 @@ def as_string(self) -> str: def __str__(self) -> str: return f"{self._trivia.indent}{decode(self._trivia.comment)}" + def unwrap(self): + return decode(self._trivia.comment).lstrip("#").lstrip() + + def __repr__(self) -> str: + return f"<{self.__class__.__name__} {self.unwrap()!r}>" + class Integer(Item, _CustomInt): """ @@ -1965,3 +1971,6 @@ def as_string(self) -> str: def _getstate(self, protocol=3) -> tuple: return () + + def __repr__(self): + return ""