@@ -29,8 +29,6 @@ | |||
| 29 | 29 | ||
| 30 | 30 | import configparser as cp | |
| 31 | 31 | ||
| 32 | - from pathlib import Path | ||
| 33 | - | ||
| 34 | 32 | # typing------------------------------------------------------- | |
| 35 | 33 | ||
| 36 | 34 | from typing import Any, Callable, IO, List, Dict, Sequence, TYPE_CHECKING, Tuple, Union, cast, overload | |
@@ -330,7 +328,7 @@ def _acquire_lock(self) -> None: | |||
| 330 | 328 | "Write-ConfigParsers can operate on a single file only, multiple files have been passed") | |
| 331 | 329 | # END single file check | |
| 332 | 330 | ||
| 333 | - if isinstance(self._file_or_files, (str, Path)): # cannot narrow by os._pathlike until 3.5 dropped | ||
| 331 | + if isinstance(self._file_or_files, (str, os.PathLike)): | ||
| 334 | 332 | file_or_files = self._file_or_files | |
| 335 | 333 | else: | |
| 336 | 334 | file_or_files = cast(IO, self._file_or_files).name | |
@@ -3,7 +3,7 @@ | |||
| 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 git.refs.reference import Reference | ||
| 6 | + | ||
| 7 | 7 | import glob | |
| 8 | 8 | from io import BytesIO | |
| 9 | 9 | import os | |
@@ -74,6 +74,7 @@ | |||
| 74 | 74 | if TYPE_CHECKING: | |
| 75 | 75 | from subprocess import Popen | |
| 76 | 76 | from git.repo import Repo | |
| 77 | + from git.refs.reference import Reference | ||
| 77 | 78 | ||
| 78 | 79 | ||
| 79 | 80 | StageType = int | |
@@ -1191,7 +1192,7 @@ def handle_stderr(proc: 'Popen[bytes]', iter_checked_out_files: Iterable[PathLik | |||
| 1191 | 1192 | assert "Should not reach this point" | |
| 1192 | 1193 | ||
| 1193 | 1194 | @default_index | |
| 1194 | - def reset(self, commit: Union[Commit, Reference, str] = 'HEAD', working_tree: bool = False, | ||
| 1195 | + def reset(self, commit: Union[Commit, 'Reference', str] = 'HEAD', working_tree: bool = False, | ||
| 1195 | 1196 | paths: Union[None, Iterable[PathLike]] = None, | |
| 1196 | 1197 | head: bool = False, **kwargs: Any) -> 'IndexFile': | |
| 1197 | 1198 | """Reset the index to reflect the tree at the given commit. This will not | |
@@ -17,15 +17,12 @@ | |||
| 17 | 17 | ||
| 18 | 18 | from typing import Any, TYPE_CHECKING, Optional, Union | |
| 19 | 19 | ||
| 20 | - from git.types import PathLike | ||
| 20 | + from git.types import PathLike, Commit_ish | ||
| 21 | 21 | ||
| 22 | 22 | if TYPE_CHECKING: | |
| 23 | 23 | from git.repo import Repo | |
| 24 | 24 | from gitdb.base import OStream | |
| 25 | - from .tree import Tree | ||
| 26 | - from .blob import Blob | ||
| 27 | - from .tag import TagObject | ||
| 28 | - from .commit import Commit | ||
| 25 | + # from .tree import Tree, Blob, Commit, TagObject | ||
| 29 | 26 | ||
| 30 | 27 | # -------------------------------------------------------------------------- | |
| 31 | 28 | ||
@@ -71,7 +68,7 @@ def new(cls, repo: 'Repo', id): # @ReservedAssignment | |||
| 71 | 68 | return repo.rev_parse(str(id)) | |
| 72 | 69 | ||
| 73 | 70 | @classmethod | |
| 74 | - def new_from_sha(cls, repo: 'Repo', sha1: bytes) -> Union['Commit', 'TagObject', 'Tree', 'Blob']: | ||
| 71 | + def new_from_sha(cls, repo: 'Repo', sha1: bytes) -> Commit_ish: | ||
| 75 | 72 | """ | |
| 76 | 73 | :return: new object instance of a type appropriate to represent the given | |
| 77 | 74 | binary sha1 | |
@@ -3,12 +3,10 @@ | |||
| 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 | - | ||
| 7 | 6 | from gitdb import IStream | |
| 8 | 7 | from git.util import ( | |
| 9 | 8 | hex_to_bin, | |
| 10 | 9 | Actor, | |
| 11 | - IterableObj, | ||
| 12 | 10 | Stats, | |
| 13 | 11 | finalize_process | |
| 14 | 12 | ) | |
@@ -17,8 +15,8 @@ | |||
| 17 | 15 | from .tree import Tree | |
| 18 | 16 | from . import base | |
| 19 | 17 | from .util import ( | |
| 20 | - Traversable, | ||
| 21 | 18 | Serializable, | |
| 19 | + TraversableIterableObj, | ||
| 22 | 20 | parse_date, | |
| 23 | 21 | altz_to_utctz_str, | |
| 24 | 22 | parse_actor_and_date, | |
@@ -36,18 +34,25 @@ | |||
| 36 | 34 | from io import BytesIO | |
| 37 | 35 | import logging | |
| 38 | 36 | ||
| 39 | - from typing import List, Tuple, Union, TYPE_CHECKING | ||
| 37 | + | ||
| 38 | + # typing ------------------------------------------------------------------ | ||
| 39 | + | ||
| 40 | + from typing import Any, Iterator, List, Sequence, Tuple, Union, TYPE_CHECKING | ||
| 41 | + | ||
| 42 | + from git.types import PathLike | ||
| 40 | 43 | ||
| 41 | 44 | if TYPE_CHECKING: | |
| 42 | 45 | from git.repo import Repo | |
| 43 | 46 | ||
| 47 | + # ------------------------------------------------------------------------ | ||
| 48 | + | ||
| 44 | 49 | log = logging.getLogger('git.objects.commit') | |
| 45 | 50 | log.addHandler(logging.NullHandler()) | |
| 46 | 51 | ||
| 47 | 52 | __all__ = ('Commit', ) | |
| 48 | 53 | ||
| 49 | 54 | ||
| 50 | - class Commit(base.Object, IterableObj, Diffable, Traversable, Serializable): | ||
| 55 | + class Commit(base.Object, TraversableIterableObj, Diffable, Serializable): | ||
| 51 | 56 | ||
| 52 | 57 | """Wraps a git Commit object. | |
| 53 | 58 | ||
@@ -73,7 +78,8 @@ class Commit(base.Object, IterableObj, Diffable, Traversable, Serializable): | |||
| 73 | 78 | "message", "parents", "encoding", "gpgsig") | |
| 74 | 79 | _id_attribute_ = "hexsha" | |
| 75 | 80 | ||
| 76 | - def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, author_tz_offset=None, | ||
| 81 | + def __init__(self, repo, binsha, tree=None, author: Union[Actor, None] = None, | ||
| 82 | + authored_date=None, author_tz_offset=None, | ||
| 77 | 83 | committer=None, committed_date=None, committer_tz_offset=None, | |
| 78 | 84 | message=None, parents: Union[Tuple['Commit', ...], List['Commit'], None] = None, | |
| 79 | 85 | encoding=None, gpgsig=None): | |
@@ -139,7 +145,7 @@ def __init__(self, repo, binsha, tree=None, author=None, authored_date=None, aut | |||
| 139 | 145 | self.gpgsig = gpgsig | |
| 140 | 146 | ||
| 141 | 147 | @classmethod | |
| 142 | - def _get_intermediate_items(cls, commit: 'Commit') -> Tuple['Commit', ...]: # type: ignore ## cos overriding super | ||
| 148 | + def _get_intermediate_items(cls, commit: 'Commit') -> Tuple['Commit', ...]: | ||
| 143 | 149 | return tuple(commit.parents) | |
| 144 | 150 | ||
| 145 | 151 | @classmethod | |
@@ -225,7 +231,9 @@ def name_rev(self): | |||
| 225 | 231 | return self.repo.git.name_rev(self) | |
| 226 | 232 | ||
| 227 | 233 | @classmethod | |
| 228 | - def iter_items(cls, repo, rev, paths='', **kwargs): | ||
| 234 | + def iter_items(cls, repo: 'Repo', rev, # type: ignore | ||
| 235 | + paths: Union[PathLike, Sequence[PathLike]] = '', **kwargs: Any | ||
| 236 | + ) -> Iterator['Commit']: | ||
| 229 | 237 | """Find all commits matching the given criteria. | |
| 230 | 238 | ||
| 231 | 239 | :param repo: is the Repo | |
@@ -245,15 +253,23 @@ def iter_items(cls, repo, rev, paths='', **kwargs): | |||
| 245 | 253 | ||
| 246 | 254 | # use -- in any case, to prevent possibility of ambiguous arguments | |
| 247 | 255 | # see https://github.com/gitpython-developers/GitPython/issues/264 | |
| 248 | - args = ['--'] | ||
| 256 | + | ||
| 257 | + args_list: List[Union[PathLike, Sequence[PathLike]]] = ['--'] | ||
| 258 | + | ||
| 249 | 259 | if paths: | |
| 250 | - args.extend((paths, )) | ||
| 260 | + paths_tup: Tuple[PathLike, ...] | ||
| 261 | + if isinstance(paths, (str, os.PathLike)): | ||
| 262 | + paths_tup = (paths, ) | ||
| 263 | + else: | ||
| 264 | + paths_tup = tuple(paths) | ||
| 265 | + | ||
| 266 | + args_list.extend(paths_tup) | ||
| 251 | 267 | # END if paths | |
| 252 | 268 | ||
| 253 | - proc = repo.git.rev_list(rev, args, as_process=True, **kwargs) | ||
| 269 | + proc = repo.git.rev_list(rev, args_list, as_process=True, **kwargs) | ||
| 254 | 270 | return cls._iter_from_process_or_stream(repo, proc) | |
| 255 | 271 | ||
| 256 | - def iter_parents(self, paths='', **kwargs): | ||
| 272 | + def iter_parents(self, paths: Union[PathLike, Sequence[PathLike]] = '', **kwargs) -> Iterator['Commit']: | ||
| 257 | 273 | """Iterate _all_ parents of this commit. | |
| 258 | 274 | ||
| 259 | 275 | :param paths: | |
@@ -269,7 +285,7 @@ def iter_parents(self, paths='', **kwargs): | |||
| 269 | 285 | ||
| 270 | 286 | return self.iter_items(self.repo, self, paths, **kwargs) | |
| 271 | 287 | ||
| 272 | - @property | ||
| 288 | + @ property | ||
| 273 | 289 | def stats(self): | |
| 274 | 290 | """Create a git stat from changes between this commit and its first parent | |
| 275 | 291 | or from all changes done if this is the very first commit. | |
@@ -286,7 +302,7 @@ def stats(self): | |||
| 286 | 302 | text = self.repo.git.diff(self.parents[0].hexsha, self.hexsha, '--', numstat=True) | |
| 287 | 303 | return Stats._list_from_string(self.repo, text) | |
| 288 | 304 | ||
| 289 | - @classmethod | ||
| 305 | + @ classmethod | ||
| 290 | 306 | def _iter_from_process_or_stream(cls, repo, proc_or_stream): | |
| 291 | 307 | """Parse out commit information into a list of Commit objects | |
| 292 | 308 | We expect one-line per commit, and parse the actual commit information directly | |
@@ -317,7 +333,7 @@ def _iter_from_process_or_stream(cls, repo, proc_or_stream): | |||
| 317 | 333 | if hasattr(proc_or_stream, 'wait'): | |
| 318 | 334 | finalize_process(proc_or_stream) | |
| 319 | 335 | ||
| 320 | - @classmethod | ||
| 336 | + @ classmethod | ||
| 321 | 337 | def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False, author=None, committer=None, | |
| 322 | 338 | author_date=None, commit_date=None): | |
| 323 | 339 | """Commit the given tree, creating a commit object. | |
0 commit comments