From a2d9011c05b0e27f1324f393e65954542544250d Mon Sep 17 00:00:00 2001 From: Yobmod Date: Fri, 25 Jun 2021 00:06:15 +0100 Subject: Add asserts and casts for T_Tree_cache --- git/objects/tree.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'git/objects/tree.py') 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: -- cgit v1.2.1