|
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 | | -fromtypingimportTuple,Union |
8 | 7 | fromgitdbimportIStream |
9 | 8 | fromgit.utilimport ( |
10 | 9 | hex_to_bin, |
|
37 | 36 | fromioimportBytesIO |
38 | 37 | importlogging |
39 | 38 |
|
| 39 | +fromtypingimportList,Tuple,Union,TYPE_CHECKING |
| 40 | + |
| 41 | +ifTYPE_CHECKING: |
| 42 | +fromgit.repoimportRepo |
| 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 | | -returncommit.parents |
| 142 | +def_get_intermediate_items(cls,commit:'Commit')->Tuple['Commit', ...]:# type: ignore ## cos overriding super |
| 143 | +returntuple(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 | forpinself.parents: |
@@ -473,7 +477,7 @@ def _serialize(self, stream): |
473 | 477 | # END handle encoding |
474 | 478 | returnself |
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 | whilebuf: |
515 | 519 | ifbuf[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 | elifbuf[0:7]==b"gpgsig ": |
519 | 523 | sig=buf[buf.find(b' ')+1:]+b"\n" |
|