| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 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,6 +36,11 @@ | |||
| 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" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,6 @@ | |||
| 3 | 3 | # | |
| 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 | - from typing import Iterable, Iterator, Tuple, Union, cast | ||
| 7 | 6 | from git.util import join_path | |
| 8 | 7 | import git.diff as diff | |
| 9 | 8 | from git.util import to_bin_sha | |
@@ -18,6 +17,17 @@ | |||
| 18 | 17 | tree_to_stream | |
| 19 | 18 | ) | |
| 20 | 19 | ||
| 20 | + | ||
| 21 | + # typing ------------------------------------------------- | ||
| 22 | + | ||
| 23 | + from typing import Iterable, Iterator, Tuple, Union, cast, TYPE_CHECKING | ||
| 24 | + | ||
| 25 | + if TYPE_CHECKING: | ||
| 26 | + from io import BytesIO | ||
| 27 | + | ||
| 28 | + #-------------------------------------------------------- | ||
| 29 | + | ||
| 30 | + | ||
| 21 | 31 | cmp = lambda a, b: (a > b) - (a < b) | |
| 22 | 32 | ||
| 23 | 33 | __all__ = ("TreeModifier", "Tree") | |
@@ -321,15 +331,15 @@ def __contains__(self, item): | |||
| 321 | 331 | def __reversed__(self): | |
| 322 | 332 | return reversed(self._iter_convert_to_object(self._cache)) | |
| 323 | 333 | ||
| 324 | - def _serialize(self, stream): | ||
| 334 | + def _serialize(self, stream: 'BytesIO') -> 'Tree': | ||
| 325 | 335 | """Serialize this tree into the stream. Please note that we will assume | |
| 326 | 336 | our tree data to be in a sorted state. If this is not the case, serialization | |
| 327 | 337 | will not generate a correct tree representation as these are assumed to be sorted | |
| 328 | 338 | by algorithms""" | |
| 329 | 339 | tree_to_stream(self._cache, stream.write) | |
| 330 | 340 | return self | |
| 331 | 341 | ||
| 332 | - def _deserialize(self, stream): | ||
| 342 | + def _deserialize(self, stream: 'BytesIO') -> 'Tree': | ||
| 333 | 343 | self._cache = tree_entries_from_data(stream.read()) | |
| 334 | 344 | return self | |
| 335 | 345 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ | |||
| 5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php | |
| 6 | 6 | """Module for general utility functions""" | |
| 7 | 7 | ||
| 8 | - | ||
| 9 | 8 | from git.util import ( | |
| 10 | 9 | IterableList, | |
| 11 | 10 | Actor | |
@@ -20,9 +19,10 @@ | |||
| 20 | 19 | from datetime import datetime, timedelta, tzinfo | |
| 21 | 20 | ||
| 22 | 21 | # typing ------------------------------------------------------------ | |
| 23 | - from typing import Any, Callable, Deque, IO, Iterator, Sequence, TYPE_CHECKING, Tuple, Type, Union, cast, overload | ||
| 22 | + from typing import (Any, Callable, Deque, IO, Iterator, Sequence, TYPE_CHECKING, Tuple, Type, Union, cast, overload) | ||
| 24 | 23 | ||
| 25 | 24 | if TYPE_CHECKING: | |
| 25 | + from io import BytesIO | ||
| 26 | 26 | from .submodule.base import Submodule | |
| 27 | 27 | from .commit import Commit | |
| 28 | 28 | from .blob import Blob | |
@@ -412,14 +412,14 @@ class Serializable(object): | |||
| 412 | 412 | """Defines methods to serialize and deserialize objects from and into a data stream""" | |
| 413 | 413 | __slots__ = () | |
| 414 | 414 | ||
| 415 | - def _serialize(self, stream): | ||
| 415 | + def _serialize(self, stream: 'BytesIO') -> 'Serializable': | ||
| 416 | 416 | """Serialize the data of this object into the given data stream | |
| 417 | 417 | :note: a serialized object would ``_deserialize`` into the same object | |
| 418 | 418 | :param stream: a file-like object | |
| 419 | 419 | :return: self""" | |
| 420 | 420 | raise NotImplementedError("To be implemented in subclass") | |
| 421 | 421 | ||
| 422 | - def _deserialize(self, stream): | ||
| 422 | + def _deserialize(self, stream: 'BytesIO') -> 'Serializable': | ||
| 423 | 423 | """Deserialize all information regarding this object from the stream | |
| 424 | 424 | :param stream: a file-like object | |
| 425 | 425 | :return: self""" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments