diff options
author | Anthon van der Neut <anthon@mnt.org> | 2023-05-01 20:07:58 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2023-05-01 20:07:58 +0200 |
commit | 913318287aacca50246fd44fa5682e3907c1c78a (patch) | |
tree | 6031c22905170e5192a3d7b649751cdcb7503cb8 | |
parent | 8b731994b1543d7886af85f926d9eea5a22d0732 (diff) | |
download | ruamel.yaml-913318287aacca50246fd44fa5682e3907c1c78a.tar.gz |
repr of commentedmap simplified
-rw-r--r-- | README.rst | 6 | ||||
-rw-r--r-- | _test/test_comments.py | 4 | ||||
-rw-r--r-- | _test/test_issues.py | 2 | ||||
-rw-r--r-- | comments.py | 6 |
4 files changed, 11 insertions, 7 deletions
@@ -70,9 +70,13 @@ ChangeLog .. should insert NEXT: at the beginning of line for next key (with empty line) NEXT: + - fix issue with indent != 2 and literal scalars with empty first line (reported by wrdis on `StackOverflow <https://stackoverflow.com/q/75584262/1307905>`__) - - updated __repr__ of CommentedMap, now that dict is ordered -> no more ordereddict + - updated __repr__ of CommentedMap, now that Python's dict is ordered -> no more + ordereddict(list-of-tuples) + - merge MR 4, handling OctalInt in YAML 1.1 + (provided by `Jacob Floyd <https://sourceforge.net/u/cognifloyd/profile/>`_) - fix loading of `!!float 42` (reported by Eric on `Stack overflow <https://stackoverflow.com/a/71555107/1307905>`_) - line numbers are now set on `CommentedKeySeq` and `CommentedKeyMap` (which diff --git a/_test/test_comments.py b/_test/test_comments.py index 64b8cd2..6c3d8c3 100644 --- a/_test/test_comments.py +++ b/_test/test_comments.py @@ -517,7 +517,7 @@ class TestCommentedMapMerge: """) assert data['x']['a'] == 1 assert data['y']['a'] == 1 - assert str(data['y']) == """ordereddict([('a', 1)])""" + assert str(data['y']) == """{'a': 1}""" def test_issue_60_1(self) -> None: data = round_trip_load(""" @@ -529,7 +529,7 @@ class TestCommentedMapMerge: """) assert data['x']['a'] == 1 assert data['y']['a'] == 1 - assert str(data['y']) == """ordereddict([('b', 2), ('a', 1)])""" + assert str(data['y']) == """{'b': 2, 'a': 1}""" class TestEmptyLines: diff --git a/_test/test_issues.py b/_test/test_issues.py index 7106453..ec90555 100644 --- a/_test/test_issues.py +++ b/_test/test_issues.py @@ -29,7 +29,7 @@ class TestIssues: """) data = round_trip_load(s) assert str(data['comb']) == str(data['def']) - assert str(data['comb']) == "ordereddict([('key', 'value'), ('key1', 'value1')])" + assert str(data['comb']) == "{'key': 'value', 'key1': 'value1'}" # def test_issue_82(self, tmpdir): # program_src = r''' diff --git a/comments.py b/comments.py index c6a9703..da2b191 100644 --- a/comments.py +++ b/comments.py @@ -866,13 +866,13 @@ class CommentedMap(ordereddict, CommentedBase): return default def __repr__(self) -> Any: - res = "ordereddict([" + res = "{" sep = '' for k, v in self.items(): - res += f'{sep}({k!r}, {v!r})' + res += f'{sep}{k!r}: {v!r}' if not sep: sep = ', ' - res += '])' + res += '}' return res def non_merged_items(self) -> Any: |