diff options
author | Yobmod <yobmod@gmail.com> | 2021-05-20 21:34:33 +0100 |
---|---|---|
committer | Yobmod <yobmod@gmail.com> | 2021-05-20 21:34:33 +0100 |
commit | c51f93823d46f0882b49822ce6f9e668228e5b8d (patch) | |
tree | 8f435f0565b3834aded4cff60e841f28618038bc /git/objects/commit.py | |
parent | 76bcd7081265f1d72fcc3101bfda62c67d8a7f32 (diff) | |
download | gitpython-c51f93823d46f0882b49822ce6f9e668228e5b8d.tar.gz |
Add types to objects _serialize() and _deserialize()
Diffstat (limited to 'git/objects/commit.py')
-rw-r--r-- | git/objects/commit.py | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/git/objects/commit.py b/git/objects/commit.py index 228e897e..26db6e36 100644 --- a/git/objects/commit.py +++ b/git/objects/commit.py @@ -4,7 +4,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 Tuple, Union from gitdb import IStream from git.util import ( hex_to_bin, @@ -37,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()) @@ -71,7 +75,7 @@ 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: Union[Tuple['Commit', ...], None] = 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. @@ -135,11 +139,11 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): self.gpgsig = gpgsig @classmethod - def _get_intermediate_items(cls, commit: 'Commit') -> Tuple['Commit', ...]: # type: ignore - 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 @@ -432,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: @@ -473,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 @@ -513,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" |