|
41 | 41 |
|
42 | 42 | from typing import Any, IO, Iterator, List, Sequence, Tuple, Union, TYPE_CHECKING |
43 | 43 |
|
44 | | -from git.types import PathLike, TypeGuard |
| 44 | +from git.types import PathLike, TypeGuard, Literal |
45 | 45 |
|
46 | 46 | if TYPE_CHECKING: |
47 | 47 | from git.repo import Repo |
| 48 | + from git.refs import SymbolicReference |
48 | 49 |
|
49 | 50 | # ------------------------------------------------------------------------ |
50 | 51 |
|
@@ -73,14 +74,14 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable): |
73 | 74 | default_encoding = "UTF-8" |
74 | 75 |
|
75 | 76 | # object configuration |
76 | | - type = "commit" |
| 77 | + type: Literal['commit'] = "commit" |
77 | 78 | __slots__ = ("tree", |
78 | 79 | "author", "authored_date", "author_tz_offset", |
79 | 80 | "committer", "committed_date", "committer_tz_offset", |
80 | 81 | "message", "parents", "encoding", "gpgsig") |
81 | 82 | _id_attribute_ = "hexsha" |
82 | 83 |
|
83 | | - def __init__(self, repo: 'Repo', binsha: bytes, tree: Union['Tree', None] = None, |
| 84 | + def __init__(self, repo: 'Repo', binsha: bytes, tree: Union[Tree, None] = None, |
84 | 85 | author: Union[Actor, None] = None, |
85 | 86 | authored_date: Union[int, None] = None, |
86 | 87 | author_tz_offset: Union[None, float] = None, |
@@ -201,11 +202,11 @@ def _set_cache_(self, attr: str) -> None: |
201 | 202 | # END handle attrs |
202 | 203 |
|
203 | 204 | @property |
204 | | - def authored_datetime(self) -> 'datetime.datetime': |
| 205 | + def authored_datetime(self) -> datetime.datetime: |
205 | 206 | return from_timestamp(self.authored_date, self.author_tz_offset) |
206 | 207 |
|
207 | 208 | @property |
208 | | - def committed_datetime(self) -> 'datetime.datetime': |
| 209 | + def committed_datetime(self) -> datetime.datetime: |
209 | 210 | return from_timestamp(self.committed_date, self.committer_tz_offset) |
210 | 211 |
|
211 | 212 | @property |
@@ -242,7 +243,7 @@ def name_rev(self) -> str: |
242 | 243 | return self.repo.git.name_rev(self) |
243 | 244 |
|
244 | 245 | @classmethod |
245 | | - def iter_items(cls, repo: 'Repo', rev: str, # type: ignore |
| 246 | + def iter_items(cls, repo: 'Repo', rev: Union[str, 'Commit', 'SymbolicReference'], # type: ignore |
246 | 247 | paths: Union[PathLike, Sequence[PathLike]] = '', **kwargs: Any |
247 | 248 | ) -> Iterator['Commit']: |
248 | 249 | """Find all commits matching the given criteria. |
@@ -354,7 +355,7 @@ def is_stream(inp) -> TypeGuard[IO]: |
354 | 355 | finalize_process(proc_or_stream) |
355 | 356 |
|
356 | 357 | @ classmethod |
357 | | - def create_from_tree(cls, repo: 'Repo', tree: Union['Tree', str], message: str, |
| 358 | + def create_from_tree(cls, repo: 'Repo', tree: Union[Tree, str], message: str, |
358 | 359 | parent_commits: Union[None, List['Commit']] = None, head: bool = False, |
359 | 360 | author: Union[None, Actor] = None, committer: Union[None, Actor] = None, |
360 | 361 | author_date: Union[None, str] = None, commit_date: Union[None, str] = None): |
@@ -516,8 +517,10 @@ def _serialize(self, stream: BytesIO) -> 'Commit': |
516 | 517 | return self |
517 | 518 |
|
518 | 519 | def _deserialize(self, stream: BytesIO) -> 'Commit': |
519 | | - """:param from_rev_list: if true, the stream format is coming from the rev-list command |
520 | | - Otherwise it is assumed to be a plain data stream from our object""" |
| 520 | + """ |
| 521 | + :param from_rev_list: if true, the stream format is coming from the rev-list command |
| 522 | + Otherwise it is assumed to be a plain data stream from our object |
| 523 | + """ |
521 | 524 | readline = stream.readline |
522 | 525 | self.tree = Tree(self.repo, hex_to_bin(readline().split()[1]), Tree.tree_id << 12, '') |
523 | 526 |
|
|
0 commit comments