summaryrefslogtreecommitdiff
path: root/git/objects/tree.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-07-09 23:33:53 +0100
committerYobmod <yobmod@gmail.com>2021-07-09 23:33:53 +0100
commite6a27adb71d21c81628acbdd65bf07037604ff90 (patch)
tree874e68e3b8027ff0e1833e55d254b6c40d07bb81 /git/objects/tree.py
parent2ea528e9fbcac850d99ce527ad4a5e4afb3587a8 (diff)
downloadgitpython-e6a27adb71d21c81628acbdd65bf07037604ff90.tar.gz
Use TreeCacheTup type alias throughout
Diffstat (limited to 'git/objects/tree.py')
-rw-r--r--git/objects/tree.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 4c2a02bf..a9656c1d 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -31,9 +31,14 @@ if TYPE_CHECKING:
from io import BytesIO
TreeCacheTup = Tuple[bytes, int, str]
+
TraversedTreeTup = Union[Tuple[Union['Tree', None], IndexObjUnion,
Tuple['Submodule', 'Submodule']]]
+
+def is_tree_cache(inp: Tuple[bytes, int, str]) -> TypeGuard[TreeCacheTup]:
+ return isinstance(inp[0], bytes) and isinstance(inp[1], int) and isinstance([inp], str)
+
#--------------------------------------------------------
@@ -141,11 +146,8 @@ class TreeModifier(object):
sha = to_bin_sha(sha)
index = self._index_by_name(name)
- def is_tree_cache(inp: Tuple[bytes, int, str]) -> TypeGuard[TreeCacheTup]:
- return isinstance(inp[0], bytes) and isinstance(inp[1], int) and isinstance([inp], str)
-
item = (sha, mode, name)
- assert is_tree_cache(item)
+ # assert is_tree_cache(item)
if index == -1:
self._cache.append(item)
@@ -223,12 +225,12 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
if attr == "_cache":
# Set the data when we need it
ostream = self.repo.odb.stream(self.binsha)
- self._cache: List[Tuple[bytes, int, str]] = tree_entries_from_data(ostream.read())
+ self._cache: List[TreeCacheTup] = tree_entries_from_data(ostream.read())
else:
super(Tree, self)._set_cache_(attr)
# END handle attribute
- def _iter_convert_to_object(self, iterable: Iterable[Tuple[bytes, int, str]]
+ def _iter_convert_to_object(self, iterable: Iterable[TreeCacheTup]
) -> Iterator[IndexObjUnion]:
"""Iterable yields tuples of (binsha, mode, name), which will be converted
to the respective object representation"""