From c712482acfab94f2eea98516e779d389476cbe04 Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Thu, 20 Mar 2025 20:03:54 -0400 Subject: [PATCH 1/5] add repr to items --- tomlkit/items.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tomlkit/items.py b/tomlkit/items.py index b80e9f1..a1b02c5 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('#').lstrip() + + def __repr__(self) -> str: + return f"<{self.__class__.__name__} {self.unwrap()!r}>" + class Integer(Item, _CustomInt): """ @@ -1419,6 +1425,12 @@ def __delitem__(self, key: int | slice): def _getstate(self, protocol=3): return list(self._iter_items()), self._trivia, self._multiline + def __repr__(self) -> str: + return repr(self._value) + + def __str__(self) -> str: + return str(self.unwrap()) + class AbstractTable(Item, _CustomDict): """Common behaviour of both :class:`Table` and :class:`InlineTable`""" @@ -1965,3 +1977,6 @@ def as_string(self) -> str: def _getstate(self, protocol=3) -> tuple: return () + + def __repr__(self): + return "" From ecf00558eeabb743ea7a076857eab9c05816ca69 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 21 Mar 2025 00:13:42 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tomlkit/items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tomlkit/items.py b/tomlkit/items.py index a1b02c5..3fc4514 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -574,7 +574,7 @@ def __str__(self) -> str: return f"{self._trivia.indent}{decode(self._trivia.comment)}" def unwrap(self): - return decode(self._trivia.comment).lstrip().lstrip('#').lstrip() + return decode(self._trivia.comment).lstrip().lstrip("#").lstrip() def __repr__(self) -> str: return f"<{self.__class__.__name__} {self.unwrap()!r}>" From a6fec042510540dfef8e13a3fa37876c2e504846 Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Sat, 22 Mar 2025 22:40:25 -0400 Subject: [PATCH 3/5] remove array repr and str --- tomlkit/items.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/tomlkit/items.py b/tomlkit/items.py index 3fc4514..a3d725b 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -1425,12 +1425,6 @@ def __delitem__(self, key: int | slice): def _getstate(self, protocol=3): return list(self._iter_items()), self._trivia, self._multiline - def __repr__(self) -> str: - return repr(self._value) - - def __str__(self) -> str: - return str(self.unwrap()) - class AbstractTable(Item, _CustomDict): """Common behaviour of both :class:`Table` and :class:`InlineTable`""" From c04b798ab9d3f518b120eb72f14b839ed6dbffcb Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Sat, 22 Mar 2025 22:40:53 -0400 Subject: [PATCH 4/5] remove unnecessary lstrip --- tomlkit/items.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tomlkit/items.py b/tomlkit/items.py index a3d725b..1c6ef8d 100644 --- a/tomlkit/items.py +++ b/tomlkit/items.py @@ -574,7 +574,7 @@ def __str__(self) -> str: return f"{self._trivia.indent}{decode(self._trivia.comment)}" def unwrap(self): - return decode(self._trivia.comment).lstrip().lstrip("#").lstrip() + return decode(self._trivia.comment).lstrip("#").lstrip() def __repr__(self) -> str: return f"<{self.__class__.__name__} {self.unwrap()!r}>" From 74dd8797b0a153b11c8731f3c30d2b4c8068426b Mon Sep 17 00:00:00 2001 From: Dimma Don't <93484965+DimmaDont@users.noreply.github.com> Date: Sat, 22 Mar 2025 22:43:21 -0400 Subject: [PATCH 5/5] add doc str test --- tests/test_items.py | 1 + 1 file changed, 1 insertion(+) 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]