Skip to content

Commit 030b1fd

Browse files
committed
Add list_traverse() to Tree and TraversableIterableObj.
1 parent f4cb7db commit 030b1fd

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

‎git/objects/tree.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This module is part of GitPython and is released under
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

7-
from git.util import join_path
7+
from git.util import IterableList, join_path
88
import git.diff as diff
99
from git.util import to_bin_sha
1010

@@ -21,7 +21,7 @@
2121

2222
# typing -------------------------------------------------
2323

24-
from typing import (Callable, Dict, Iterable, Iterator, List,
24+
from typing import (Any, Callable, Dict, Iterable, Iterator, List,
2525
Tuple, Type, Union, cast, TYPE_CHECKING)
2626

2727
from git.types import PathLike, TypeGuard
@@ -323,6 +323,9 @@ def traverse(self, # type: ignore # overrides super()
323323
super(Tree, self).traverse(predicate, prune, depth, # type: ignore
324324
branch_first, visit_once, ignore_self))
325325

326+
def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[Union['Tree', 'Submodule', 'Blob']]:
327+
return super(Tree, self).list_traverse(* args, **kwargs)
328+
326329
# List protocol
327330

328331
def __getslice__(self, i: int, j: int) -> List[IndexObjUnion]:

‎git/objects/util.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import calendar
2020
from datetime import datetime, timedelta, tzinfo
2121

22+
from git.objects.base import IndexObject # just for an isinstance check
23+
2224
# typing ------------------------------------------------------------
2325
from typing import (Any, Callable, Deque, Iterator, NamedTuple, overload, Sequence,
2426
TYPE_CHECKING, Tuple, Type, TypeVar, Union, cast)
@@ -317,7 +319,7 @@ def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[Union['Commit
317319
"""
318320
# Commit and Submodule have id.__attribute__ as IterableObj
319321
# Tree has id.__attribute__ inherited from IndexObject
320-
if isinstance(self, (TraversableIterableObj, Tree)):
322+
if isinstance(self, (TraversableIterableObj, IndexObject)):
321323
id = self._id_attribute_
322324
else:
323325
id = "" # shouldn't reach here, unless Traversable subclass created with no _id_attribute_
@@ -456,6 +458,9 @@ class TraversableIterableObj(Traversable, IterableObj):
456458

457459
TIobj_tuple = Tuple[Union[T_TIobj, None], T_TIobj]
458460

461+
def list_traverse(self: T_TIobj, *args: Any, **kwargs: Any) -> IterableList[T_TIobj]: # type: ignore[override]
462+
return super(TraversableIterableObj, self).list_traverse(* args, **kwargs)
463+
459464
@ overload # type: ignore
460465
def traverse(self: T_TIobj,
461466
predicate: Callable[[Union[T_TIobj, Tuple[Union[T_TIobj, None], T_TIobj]], int], bool],

0 commit comments

Comments
 (0)