summaryrefslogtreecommitdiff
path: root/git/objects
diff options
context:
space:
mode:
Diffstat (limited to 'git/objects')
-rw-r--r--git/objects/base.py3
-rw-r--r--git/objects/commit.py6
-rw-r--r--git/objects/submodule/base.py13
-rw-r--r--git/objects/tree.py4
-rw-r--r--git/objects/util.py12
5 files changed, 20 insertions, 18 deletions
diff --git a/git/objects/base.py b/git/objects/base.py
index 64f105ca..a3b0f230 100644
--- a/git/objects/base.py
+++ b/git/objects/base.py
@@ -25,6 +25,7 @@ if TYPE_CHECKING:
from .tree import Tree
from .blob import Blob
from .submodule.base import Submodule
+ from git.refs.reference import Reference
IndexObjUnion = Union['Tree', 'Blob', 'Submodule']
@@ -59,7 +60,7 @@ class Object(LazyMixin):
assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % (binsha, len(binsha))
@classmethod
- def new(cls, repo: 'Repo', id): # @ReservedAssignment
+ def new(cls, repo: 'Repo', id: Union[str, 'Reference']) -> Commit_ish:
"""
:return: New Object instance of a type appropriate to the object type behind
id. The id of the newly created object will be a binsha even though
diff --git a/git/objects/commit.py b/git/objects/commit.py
index 9d709656..b689167f 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -282,7 +282,7 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
proc = repo.git.rev_list(rev, args_list, as_process=True, **kwargs)
return cls._iter_from_process_or_stream(repo, proc)
- def iter_parents(self, paths: Union[PathLike, Sequence[PathLike]] = '', **kwargs) -> Iterator['Commit']:
+ def iter_parents(self, paths: Union[PathLike, Sequence[PathLike]] = '', **kwargs: Any) -> Iterator['Commit']:
"""Iterate _all_ parents of this commit.
:param paths:
@@ -362,7 +362,7 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
def create_from_tree(cls, repo: 'Repo', tree: Union[Tree, str], message: str,
parent_commits: Union[None, List['Commit']] = None, head: bool = False,
author: Union[None, Actor] = None, committer: Union[None, Actor] = None,
- author_date: Union[None, str] = None, commit_date: Union[None, str] = None):
+ author_date: Union[None, str] = None, commit_date: Union[None, str] = None) -> 'Commit':
"""Commit the given tree, creating a commit object.
:param repo: Repo object the commit should be part of
@@ -403,7 +403,7 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
else:
for p in parent_commits:
if not isinstance(p, cls):
- raise ValueError("Parent commit '%r' must be of type %s" % (p, cls))
+ raise ValueError(f"Parent commit '{p!r}' must be of type {cls}")
# end check parent commit types
# END if parent commits are unset
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index 14351190..559d2585 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -57,6 +57,7 @@ from git.types import Commit_ish, Literal, PathLike, TBD
if TYPE_CHECKING:
from git.index import IndexFile
from git.repo import Repo
+ from git.refs import Head
# -----------------------------------------------------------------------------
@@ -265,7 +266,7 @@ class Submodule(IndexObject, TraversableIterableObj):
# end
@classmethod
- def _clone_repo(cls, repo, url, path, name, **kwargs):
+ def _clone_repo(cls, repo: 'Repo', url: str, path: PathLike, name: str, **kwargs: Any) -> 'Repo':
""":return: Repo instance of newly cloned repository
:param repo: our parent repository
:param url: url to clone from
@@ -279,7 +280,7 @@ class Submodule(IndexObject, TraversableIterableObj):
module_abspath_dir = osp.dirname(module_abspath)
if not osp.isdir(module_abspath_dir):
os.makedirs(module_abspath_dir)
- module_checkout_path = osp.join(repo.working_tree_dir, path)
+ module_checkout_path = osp.join(str(repo.working_tree_dir), path)
# end
clone = git.Repo.clone_from(url, module_checkout_path, **kwargs)
@@ -484,7 +485,7 @@ class Submodule(IndexObject, TraversableIterableObj):
def update(self, recursive: bool = False, init: bool = True, to_latest_revision: bool = False,
progress: Union['UpdateProgress', None] = None, dry_run: bool = False,
force: bool = False, keep_going: bool = False, env: Union[Mapping[str, str], None] = None,
- clone_multi_options: Union[Sequence[TBD], None] = None):
+ clone_multi_options: Union[Sequence[TBD], None] = None) -> 'Submodule':
"""Update the repository of this submodule to point to the checkout
we point at with the binsha of this instance.
@@ -712,7 +713,7 @@ class Submodule(IndexObject, TraversableIterableObj):
return self
@unbare_repo
- def move(self, module_path, configuration=True, module=True):
+ def move(self, module_path: PathLike, configuration: bool = True, module: bool = True) -> 'Submodule':
"""Move the submodule to a another module path. This involves physically moving
the repository at our current path, changing the configuration, as well as
adjusting our index entry accordingly.
@@ -742,7 +743,7 @@ class Submodule(IndexObject, TraversableIterableObj):
return self
# END handle no change
- module_checkout_abspath = join_path_native(self.repo.working_tree_dir, module_checkout_path)
+ module_checkout_abspath = join_path_native(str(self.repo.working_tree_dir), module_checkout_path)
if osp.isfile(module_checkout_abspath):
raise ValueError("Cannot move repository onto a file: %s" % module_checkout_abspath)
# END handle target files
@@ -1160,7 +1161,7 @@ class Submodule(IndexObject, TraversableIterableObj):
# END handle object state consistency
@property
- def branch(self):
+ def branch(self) -> 'Head':
""":return: The branch instance that we are to checkout
:raise InvalidGitRepositoryError: if our module is not yet checked out"""
return mkhead(self.module(), self._branch_path)
diff --git a/git/objects/tree.py b/git/objects/tree.py
index 70f36af5..0cceb59a 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -375,8 +375,8 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
# END for each item
return False
- def __reversed__(self):
- return reversed(self._iter_convert_to_object(self._cache))
+ def __reversed__(self) -> Iterator[IndexObjUnion]:
+ return reversed(self._iter_convert_to_object(self._cache)) # type: ignore
def _serialize(self, stream: 'BytesIO') -> 'Tree':
"""Serialize this tree into the stream. Please note that we will assume
diff --git a/git/objects/util.py b/git/objects/util.py
index db7807c2..f627211e 100644
--- a/git/objects/util.py
+++ b/git/objects/util.py
@@ -144,20 +144,20 @@ class tzoffset(tzinfo):
def __reduce__(self) -> Tuple[Type['tzoffset'], Tuple[float, str]]:
return tzoffset, (-self._offset.total_seconds(), self._name)
- def utcoffset(self, dt) -> timedelta:
+ def utcoffset(self, dt: Union[datetime, None]) -> timedelta:
return self._offset
- def tzname(self, dt) -> str:
+ def tzname(self, dt: Union[datetime, None]) -> str:
return self._name
- def dst(self, dt) -> timedelta:
+ def dst(self, dt: Union[datetime, None]) -> timedelta:
return ZERO
utc = tzoffset(0, 'UTC')
-def from_timestamp(timestamp, tz_offset: float) -> datetime:
+def from_timestamp(timestamp: float, tz_offset: float) -> datetime:
"""Converts a timestamp + tz_offset into an aware datetime instance."""
utc_dt = datetime.fromtimestamp(timestamp, utc)
try:
@@ -305,7 +305,7 @@ class Traversable(Protocol):
@classmethod
@abstractmethod
- def _get_intermediate_items(cls, item) -> Sequence['Traversable']:
+ def _get_intermediate_items(cls, item: Any) -> Sequence['Traversable']:
"""
Returns:
Tuple of items connected to the given item.
@@ -327,7 +327,7 @@ class Traversable(Protocol):
stacklevel=2)
return self._list_traverse(*args, **kwargs)
- def _list_traverse(self, as_edge=False, *args: Any, **kwargs: Any
+ def _list_traverse(self, as_edge: bool = False, *args: Any, **kwargs: Any
) -> IterableList[Union['Commit', 'Submodule', 'Tree', 'Blob']]:
"""
:return: IterableList with the results of the traversal as produced by