8000 Change type of list_traverse() again. · gitpython-developers/GitPython@f4cb7db · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f4cb7db

Browse files
committed
Change type of list_traverse() again.
1 parent 1faa25f commit f4cb7db

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

git/objects/util.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from .tag import TagObject
3333
from .tree import Tree, TraversedTreeTup
3434
from subprocess import Popen
35+
from .submodule.base import Submodule
3536

3637

3738
T_TIobj = TypeVar('T_TIobj', bound='TraversableIterableObj') # for TraversableIterableObj.traverse()
@@ -306,18 +307,28 @@ class Tree:: (cls, Tree) -> Tuple[Tree, ...]
306307
"""
307308
raise NotImplementedError("To be implemented in subclass")
308309

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']]:
310311
"""
311312
:return: IterableList with the results of the traversal as produced by
312313
traverse()
314+
Commit -> IterableList['Commit']
315+
Submodule -> IterableList['Submodule']
316+
Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']]
313317
"""
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)):
315321
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']]]
318329

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
321332
return out
322333

323334
def traverse(self,

0 commit comments

Comments
 (0)
0