summaryrefslogtreecommitdiff
path: root/git/objects/commit.py
diff options
context:
space:
mode:
authorYobmod <yobmod@gmail.com>2021-06-23 02:22:34 +0100
committerYobmod <yobmod@gmail.com>2021-06-23 02:22:34 +0100
commit5b6fe83f4d817a3b73b44df16cfb4f96bd4d9904 (patch)
treee9030835ef3a199a650e9d948c03eea99a09696d /git/objects/commit.py
parent7ca97dcef3131a11dd5ef41d674bb6bd36608608 (diff)
downloadgitpython-5b6fe83f4d817a3b73b44df16cfb4f96bd4d9904.tar.gz
Update typing-extensions version in requirements.txt
Diffstat (limited to 'git/objects/commit.py')
-rw-r--r--git/objects/commit.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py
index 45e6d772..26db6e36 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -36,6 +36,11 @@ import os
from io import BytesIO
import logging
+from typing import List, Tuple, Union, TYPE_CHECKING
+
+if TYPE_CHECKING:
+ from git.repo import Repo
+
log = logging.getLogger('git.objects.commit')
log.addHandler(logging.NullHandler())
@@ -70,7 +75,8 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None,
committer=None, committed_date=None, committer_tz_offset=None,
- message=None, parents=None, encoding=None, gpgsig=None):
+ message=None, parents: Union[Tuple['Commit', ...], List['Commit'], None] = None,
+ encoding=None, gpgsig=None):
"""Instantiate a new Commit. All keyword arguments taking None as default will
be implicitly set on first query.
@@ -133,11 +139,11 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
self.gpgsig = gpgsig
@classmethod
- def _get_intermediate_items(cls, commit):
- return commit.parents
+ def _get_intermediate_items(cls, commit: 'Commit') -> Tuple['Commit', ...]: # type: ignore ## cos overriding super
+ return tuple(commit.parents)
@classmethod
- def _calculate_sha_(cls, repo, commit):
+ def _calculate_sha_(cls, repo: 'Repo', commit: 'Commit') -> bytes:
'''Calculate the sha of a commit.
:param repo: Repo object the commit should be part of
@@ -430,7 +436,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
#{ Serializable Implementation
- def _serialize(self, stream):
+ def _serialize(self, stream: BytesIO) -> 'Commit':
write = stream.write
write(("tree %s\n" % self.tree).encode('ascii'))
for p in self.parents:
@@ -471,7 +477,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
# END handle encoding
return self
- def _deserialize(self, stream):
+ def _deserialize(self, stream: BytesIO) -> 'Commit':
""":param from_rev_list: if true, the stream format is coming from the rev-list command
Otherwise it is assumed to be a plain data stream from our object"""
readline = stream.readline
@@ -511,7 +517,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable):
buf = enc.strip()
while buf:
if buf[0:10] == b"encoding ":
- self.encoding = buf[buf.find(' ') + 1:].decode(
+ self.encoding = buf[buf.find(b' ') + 1:].decode(
self.encoding, 'ignore')
elif buf[0:7] == b"gpgsig ":
sig = buf[buf.find(b' ') + 1:] + b"\n"