Skip to content

Commit 217afe2

Browse files
committed
simplify: use direct node.children check instead of has_children() method
Even simpler approach: - Replace node.has_children() with direct if node.children: - Remove unnecessary has_children() methods from all classes - Pythonic and direct - empty lists are falsy, non-empty are truthy - Less code, same functionality This is the most straightforward way to check for children in Python.
1 parent 5efe631 commit 217afe2

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

src/gitingest/output_formatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def _create_tree_structure(
156156
display_name = node.get_display_name()
157157
tree_str += f"{prefix}{current_prefix}{display_name}\n"
158158

159-
if node.has_children():
159+
if node.children:
160160
prefix += " " if is_last else "│ "
161161
for i, child in enumerate(node.children):
162162
tree_str += _create_tree_structure(query, node=child, prefix=prefix, is_last=i == len(node.children) - 1)

src/gitingest/schemas/filesystem.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,7 @@ def get_display_name(self) -> str:
112112
"""Get display name for tree view. Override in subclasses."""
113113
return self.name
114114

115-
def has_children(self) -> bool:
116-
"""Return whether this node has children to display."""
117-
return False
115+
118116

119117
@property
120118
def content(self) -> str:
@@ -167,9 +165,7 @@ def get_display_name(self) -> str:
167165
"""Directories get a trailing slash."""
168166
return self.name + "/"
169167

170-
def has_children(self) -> bool:
171-
"""Directories have children if the list is not empty."""
172-
return bool(self.children)
168+
173169

174170
def render_tree(self, prefix: str = "", *, is_last: bool = True) -> list[str]:
175171
"""Render the tree representation of this directory."""

0 commit comments

Comments
 (0)