summaryrefslogtreecommitdiff
path: root/git/objects/tree.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-06-25 00:06:15 +0100
committerYobmod <yobmod@gmail.com>2021-06-25 00:06:15 +0100
commita2d9011c05b0e27f1324f393e65954542544250d (patch)
tree70bb0581ad35a0164f5174f7b36b782644459021 /git/objects/tree.py
parentfb3fec340f89955a4b0adfd64636d26300d22af9 (diff)
downloadgitpython-a2d9011c05b0e27f1324f393e65954542544250d.tar.gz
Add asserts and casts for T_Tree_cache
Diffstat (limited to 'git/objects/tree.py')
-rw-r--r--git/objects/tree.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 97a4b748..191fe27c 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -136,7 +136,9 @@ class TreeModifier(Generic[T_Tree_cache], object):
sha = to_bin_sha(sha)
index = self._index_by_name(name)
- item: T_Tree_cache = (sha, mode, name) # type: ignore ## use Typeguard from typing-extensions 3.10.0
+
+ assert isinstance(sha, bytes) and isinstance(mode, int) and isinstance(name, str)
+ item = cast(T_Tree_cache, (sha, mode, name)) # use Typeguard from typing-extensions 3.10.0
if index == -1:
self._cache.append(item)
else:
@@ -151,14 +153,17 @@ class TreeModifier(Generic[T_Tree_cache], object):
# END handle name exists
return self
- def add_unchecked(self, binsha, mode, name):
+ def add_unchecked(self, binsha: bytes, mode: int, name: str) -> None:
"""Add the given item to the tree, its correctness is assumed, which
puts the caller into responsibility to assure the input is correct.
For more information on the parameters, see ``add``
:param binsha: 20 byte binary sha"""
- self._cache.append((binsha, mode, name))
+ assert isinstance(binsha, bytes) and isinstance(mode, int) and isinstance(name, str)
+ tree_cache = cast(T_Tree_cache, (binsha, mode, name))
+
+ self._cache.append(tree_cache)
- def __delitem__(self, name):
+ def __delitem__(self, name: str) -> None:
"""Deletes an item with the given name if it exists"""
index = self._index_by_name(name)
if index > -1: