|
32 | 32 | from .tag import TagObject
|
33 | 33 | from .tree import Tree, TraversedTreeTup
|
34 | 34 | from subprocess import Popen
|
| 35 | + from .submodule.base import Submodule |
35 | 36 |
|
36 | 37 |
|
37 | 38 | T_TIobj = TypeVar('T_TIobj', bound='TraversableIterableObj') # for TraversableIterableObj.traverse()
|
@@ -306,18 +307,28 @@ class Tree:: (cls, Tree) -> Tuple[Tree, ...]
|
306 | 307 | """
|
307 | 308 | raise NotImplementedError("To be implemented in subclass")
|
308 | 309 |
|
309 |
| - def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList: |
| 310 | + def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[Union['Commit', 'Submodule', 'Tree', 'Blob']]: |
310 | 311 | """
|
311 | 312 | :return: IterableList with the results of the traversal as produced by
|
312 | 313 | traverse()
|
| 314 | + Commit -> IterableList['Commit'] |
| 315 | + Submodule -> IterableList['Submodule'] |
| 316 | + Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']] |
313 | 317 | """
|
314 |
| - if isinstance(self, TraversableIterableObj): |
| 318 | + # Commit and Submodule have id.__attribute__ as IterableObj |
| 319 | + # Tree has id.__attribute__ inherited from IndexObject |
| 320 | + if isinstance(self, (TraversableIterableObj, Tree)): |
315 | 321 | id = self._id_attribute_
|
316 |
| - else: # Tree |
317 |
| - id = "" |
| 322 | + else: |
| 323 | + id = "" # shouldn't reach here, unless Traversable subclass created with no _id_attribute_ |
| 324 | + # could add _id_attribute_ to Traversable, or make all Traversable also Iterable? |
| 325 | + |
| 326 | + out: IterableList[Union['Commit', 'Submodule', 'Tree', 'Blob']] = IterableList(id) |
| 327 | + # overloads in subclasses (mypy does't allow typing self: subclass) |
| 328 | + # Union[IterableList['Commit'], IterableList['Submodule'], IterableList[Union['Submodule', 'Tree', 'Blob']]] |
318 | 329 |
|
319 |
| - out: IterableList = IterableList(id) |
320 |
| - out.extend(self.traverse(*args, **kwargs)) |
| 330 | + # NOTE: if is_edge=True, self.traverse returns a Tuple, so should be prevented or flattened? |
| 331 | + out.extend(self.traverse(*args, **kwargs)) # type: ignore |
321 | 332 | return out
|
322 | 333 |
|
323 | 334 | def traverse(self,
|
|
0 commit comments