Skip to content

Commit 01f4ec9

Browse files
Chris1221claude
andcommitted
fix: skip ListElement objects when rendering mixed MetaEntry to avoid crash
When a YAML list mixes dict items (- x: 123) and plain strings (- y), the parser produces a MetaEntry with both Entry and ListElement children. ListElement has no to_markdown() method, causing an AttributeError. Closes #27. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7707089 commit 01f4ec9

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

test/test_examples.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,18 @@ def test_simple_no_schema(self):
237237

238238

239239

240-
class TestComments(unittest.TestCase):
240+
class TestEdgeCases(unittest.TestCase):
241241
def test_ordinary_comment_without_colon(self):
242242
# Regression test for issue #26
243243
output = get_output("test/yaml/ordinary_comments.yaml")
244244
self.assertIn("hello world", output)
245245
self.assertIn("1", output)
246246

247+
def test_mixed_list_does_not_crash(self):
248+
# Regression test for issue #27
249+
output = get_output("test/yaml/mixed_list.yaml")
250+
self.assertIn("a_list_of_mixed_dict_and_str", output)
251+
247252

248253
class TestPackage(unittest.TestCase):
249254
def test_version_is_set(self):

test/yaml/mixed_list.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#' hello world
2+
a: 1
3+
4+
a_list_of_mixed_dict_and_str:
5+
- x: 123
6+
- y

yamldoc/entries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def __repr__(self):
8282

8383
def non_excluded_entries(self):
8484
"""Returns a list of entries that are not excluded."""
85-
return [entry for entry in self.entries if not entry.exclude]
85+
return [entry for entry in self.entries if not entry.exclude and not isinstance(entry, ListElement)]
8686

8787
def table_header(self, schema=False):
8888
if schema:

0 commit comments

Comments
 (0)