|
4 | 4 | # This module is part of GitPython and is released under |
5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php |
6 | 6 |
|
7 | | -from typing import Tuple, Union |
8 | 7 | from gitdb import IStream |
9 | 8 | from git.util import ( |
10 | 9 | hex_to_bin, |
|
37 | 36 | from io import BytesIO |
38 | 37 | import logging |
39 | 38 |
|
| 39 | +from typing import List, Tuple, Union, TYPE_CHECKING |
| 40 | + |
| 41 | +if TYPE_CHECKING: |
| 42 | + from git.repo import Repo |
| 43 | + |
40 | 44 | log = logging.getLogger('git.objects.commit') |
41 | 45 | log.addHandler(logging.NullHandler()) |
42 | 46 |
|
@@ -71,7 +75,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): |
71 | 75 |
|
72 | 76 | def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None, |
73 | 77 | committer=None, committed_date=None, committer_tz_offset=None, |
74 | | - message=None, parents: Union[Tuple['Commit', ...], None] = None, |
| 78 | + message=None, parents: Union[Tuple['Commit', ...], List['Commit'], None] = None, |
75 | 79 | encoding=None, gpgsig=None): |
76 | 80 | """Instantiate a new Commit. All keyword arguments taking None as default will |
77 | 81 | be implicitly set on first query. |
@@ -135,11 +139,11 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut |
135 | 139 | self.gpgsig = gpgsig |
136 | 140 |
|
137 | 141 | @classmethod |
138 | | - def _get_intermediate_items(cls, commit: 'Commit') -> Tuple['Commit', ...]: # type: ignore |
139 | | - return commit.parents |
| 142 | + def _get_intermediate_items(cls, commit: 'Commit') -> Tuple['Commit', ...]: # type: ignore ## cos overriding super |
| 143 | + return tuple(commit.parents) |
140 | 144 |
|
141 | 145 | @classmethod |
142 | | - def _calculate_sha_(cls, repo, commit): |
| 146 | + def _calculate_sha_(cls, repo: 'Repo', commit: 'Commit') -> bytes: |
143 | 147 | '''Calculate the sha of a commit. |
144 | 148 |
|
145 | 149 | :param repo: Repo object the commit should be part of |
@@ -432,7 +436,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False, |
432 | 436 |
|
433 | 437 | #{ Serializable Implementation |
434 | 438 |
|
435 | | - def _serialize(self, stream): |
| 439 | + def _serialize(self, stream: BytesIO) -> 'Commit': |
436 | 440 | write = stream.write |
437 | 441 | write(("tree %s\n" % self.tree).encode('ascii')) |
438 | 442 | for p in self.parents: |
@@ -473,7 +477,7 @@ def _serialize(self, stream): |
473 | 477 | # END handle encoding |
474 | 478 | return self |
475 | 479 |
|
476 | | - def _deserialize(self, stream): |
| 480 | + def _deserialize(self, stream: BytesIO) -> 'Commit': |
477 | 481 | """:param from_rev_list: if true, the stream format is coming from the rev-list command |
478 | 482 | Otherwise it is assumed to be a plain data stream from our object""" |
479 | 483 | readline = stream.readline |
@@ -513,7 +517,7 @@ def _deserialize(self, stream): |
513 | 517 | buf = enc.strip() |
514 | 518 | while buf: |
515 | 519 | if buf[0:10] == b"encoding ": |
516 | | - self.encoding = buf[buf.find(' ') + 1:].decode( |
| 520 | + self.encoding = buf[buf.find(b' ') + 1:].decode( |
517 | 521 | self.encoding, 'ignore') |
518 | 522 | elif buf[0:7] == b"gpgsig ": |
519 | 523 | sig = buf[buf.find(b' ') + 1:] + b"\n" |
|
0 commit comments