summaryrefslogtreecommitdiff
path: root/git/objects/tree.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-05-20 21:34:33 +0100
committerYobmod <yobmod@gmail.com>2021-05-20 21:34:33 +0100
commitc51f93823d46f0882b49822ce6f9e668228e5b8d (patch)
tree8f435f0565b3834aded4cff60e841f28618038bc /git/objects/tree.py
parent76bcd7081265f1d72fcc3101bfda62c67d8a7f32 (diff)
downloadgitpython-c51f93823d46f0882b49822ce6f9e668228e5b8d.tar.gz
Add types to objects _serialize() and _deserialize()
Diffstat (limited to 'git/objects/tree.py')
-rw-r--r--git/objects/tree.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 65c9be4c..29b2a684 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -3,7 +3,6 @@
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
-from typing import Iterable, Iterator, Tuple, Union, cast
from git.util import join_path
import git.diff as diff
from git.util import to_bin_sha
@@ -18,6 +17,17 @@ from .fun import (
tree_to_stream
)
+
+# typing -------------------------------------------------
+
+from typing import Iterable, Iterator, Tuple, Union, cast, TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from io import BytesIO
+
+#--------------------------------------------------------
+
+
cmp = lambda a, b: (a > b) - (a < b)
__all__ = ("TreeModifier", "Tree")
@@ -321,7 +331,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
def __reversed__(self):
return reversed(self._iter_convert_to_object(self._cache))
- def _serialize(self, stream):
+ def _serialize(self, stream: 'BytesIO') -> 'Tree':
"""Serialize this tree into the stream. Please note that we will assume
our tree data to be in a sorted state. If this is not the case, serialization
will not generate a correct tree representation as these are assumed to be sorted
@@ -329,7 +339,7 @@ class Tree(IndexObject, diff.Diffable, util.Traversable, util.Serializable):
tree_to_stream(self._cache, stream.write)
return self
- def _deserialize(self, stream):
+ def _deserialize(self, stream: 'BytesIO') -> 'Tree':
self._cache = tree_entries_from_data(stream.read())
return self