Skip to content

Commit

Permalink
Merge pull request #18 from takuyaa/fix-recursion-error-article-range
Browse files Browse the repository at this point in the history
Fix RecursionError when accessing article_range
  • Loading branch information
takuyaa authored Jan 9, 2024
2 parents 7e97e3a + d192e21 commit 1fea865
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ja_law_parser/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,9 @@ class WithArticleRange(BaseXmlModel, arbitrary_types_allowed=True):

@computed_element(tag="ArticleRange") # type: ignore[arg-type]
def article_range(self) -> Optional[ArticleRange]:
if self.article_range is None:
if self.article_range_raw is None:
return None
return ArticleRange(raw_element=self.article_range)
return ArticleRange(raw_element=self.article_range_raw)

article_range_raw: Optional[etree._Element] = element(tag="ArticleRange", default=None, exclude=True)

Expand Down
32 changes: 32 additions & 0 deletions tests/test_toc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from ja_law_parser.model import TOC


class TestTOC:
def test_toc(self):
xml = """\
<TOC>
<TOCLabel>目次</TOCLabel>
<TOCChapter Num="1">
<ChapterTitle>Chapter 1</ChapterTitle>
<ArticleRange>(第一条・第二条)</ArticleRange>
</TOCChapter>
<TOCChapter Num="2">
<ChapterTitle>Chapter 2</ChapterTitle>
<ArticleRange>(第三条―第五条)</ArticleRange>
</TOCChapter>
<TOCSupplProvision>
<SupplProvisionLabel>附則</SupplProvisionLabel>
</TOCSupplProvision>
</TOC>
"""
toc: TOC = TOC.from_xml(xml)
assert toc is not None
assert toc.toc_label == "目次"
assert len(toc.toc_chapters) == 2
assert toc.toc_chapters[0].num == "1"
assert toc.toc_chapters[0].chapter_title.text == "Chapter 1"
assert toc.toc_chapters[0].article_range.text == "(第一条・第二条)"
assert toc.toc_chapters[1].num == "2"
assert toc.toc_chapters[1].chapter_title.text == "Chapter 2"
assert toc.toc_chapters[1].article_range.text == "(第三条―第五条)"
assert toc.toc_suppl_provision.suppl_provision_label.text == "附則"

0 comments on commit 1fea865

Please sign in to comment.