summaryrefslogtreecommitdiff
path: root/git/objects/tree.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-07-08 21:42:30 +0100
committerYobmod <yobmod@gmail.com>2021-07-08 21:42:30 +0100
commit5d3818ed3d51d400517a352b5b62e966164af8cf (patch)
treef58e6f846ec24da39ac05f3f44a752f1addece80 /git/objects/tree.py
parent2e2fe186d09272c3cb6c96467fff362deb90994f (diff)
downloadgitpython-5d3818ed3d51d400517a352b5b62e966164af8cf.tar.gz
Finish initial typing of index folder
Diffstat (limited to 'git/objects/tree.py')
-rw-r--r--git/objects/tree.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 34fb93dc..528cf5ca 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -21,8 +21,8 @@ from .fun import (
# typing -------------------------------------------------
-from typing import (Callable, Dict, Generic, Iterable, Iterator, List,
- Tuple, Type, TypeVar, Union, cast, TYPE_CHECKING)
+from typing import (Callable, Dict, Iterable, Iterator, List,
+ Tuple, Type, Union, cast, TYPE_CHECKING)
from git.types import PathLike, TypeGuard
@@ -30,7 +30,7 @@ if TYPE_CHECKING:
from git.repo import Repo
from io import BytesIO
-T_Tree_cache = TypeVar('T_Tree_cache', bound=Tuple[bytes, int, str])
+TreeCacheTup = Tuple[bytes, int, str]
TraversedTreeTup = Union[Tuple[Union['Tree', None], IndexObjUnion,
Tuple['Submodule', 'Submodule']]]
@@ -42,7 +42,7 @@ cmp: Callable[[str, str], int] = lambda a, b: (a > b) - (a < b)
__all__ = ("TreeModifier", "Tree")
-def git_cmp(t1: T_Tree_cache, t2: T_Tree_cache) -> int:
+def git_cmp(t1: TreeCacheTup, t2: TreeCacheTup) -> int:
a, b = t1[2], t2[2]
assert isinstance(a, str) and isinstance(b, str) # Need as mypy 9.0 cannot unpack TypeVar properly
len_a, len_b = len(a), len(b)
@@ -55,8 +55,8 @@ def git_cmp(t1: T_Tree_cache, t2: T_Tree_cache) -> int:
return len_a - len_b
-def merge_sort(a: List[T_Tree_cache],
- cmp: Callable[[T_Tree_cache, T_Tree_cache], int]) -> None:
+def merge_sort(a: List[TreeCacheTup],
+ cmp: Callable[[TreeCacheTup, TreeCacheTup], int]) -> None:
if len(a) < 2:
return None
@@ -91,7 +91,7 @@ def merge_sort(a: List[T_Tree_cache],
k = k + 1
-class TreeModifier(Generic[T_Tree_cache], object):
+class TreeModifier(object):
"""A utility class providing methods to alter the underlying cache in a list-like fashion.
@@ -99,7 +99,7 @@ class TreeModifier(Generic[T_Tree_cache], object):
the cache of a tree, will be sorted. Assuring it will be in a serializable state"""
__slots__ = '_cache'
- def __init__(self, cache: List[T_Tree_cache]) -> None:
+ def __init__(self, cache: List[TreeCacheTup]) -> None:
self._cache = cache
def _index_by_name(self, name: str) -> int:
@@ -141,7 +141,7 @@ class TreeModifier(Generic[T_Tree_cache], object):
sha = to_bin_sha(sha)
index = self._index_by_name(name)
- def is_tree_cache(inp: Tuple[bytes, int, str]) -> TypeGuard[T_Tree_cache]:
+ 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)
@@ -167,7 +167,7 @@ class TreeModifier(Generic[T_Tree_cache], object):
For more information on the parameters, see ``add``
:param binsha: 20 byte binary sha"""
assert isinstance(binsha, bytes) and isinstance(mode, int) and isinstance(name, str)
- tree_cache = cast(T_Tree_cache, (binsha, mode, name))
+ tree_cache = (binsha, mode, name)
self._cache.append(tree_cache)