summaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
Diffstat (limited to 'git')
-rw-r--r--git/objects/base.py6
-rw-r--r--git/objects/blob.py4
-rw-r--r--git/objects/commit.py21
-rw-r--r--git/objects/fun.py2
-rw-r--r--git/objects/submodule/base.py4
-rw-r--r--git/objects/tag.py4
-rw-r--r--git/objects/tree.py12
7 files changed, 30 insertions, 23 deletions
diff --git a/git/objects/base.py b/git/objects/base.py
index 4e2ed493..64f105ca 100644
--- a/git/objects/base.py
+++ b/git/objects/base.py
@@ -15,9 +15,9 @@ from .util import get_object_type_by_name
# typing ------------------------------------------------------------------
-from typing import Any, TYPE_CHECKING, Optional, Union
+from typing import Any, TYPE_CHECKING, Union
-from git.types import PathLike, Commit_ish
+from git.types import PathLike, Commit_ish, Lit_commit_ish
if TYPE_CHECKING:
from git.repo import Repo
@@ -44,7 +44,7 @@ class Object(LazyMixin):
TYPES = (dbtyp.str_blob_type, dbtyp.str_tree_type, dbtyp.str_commit_type, dbtyp.str_tag_type)
__slots__ = ("repo", "binsha", "size")
- type = None # type: Optional[str] # to be set by subclass
+ type: Union[Lit_commit_ish, None] = None
def __init__(self, repo: 'Repo', binsha: bytes):
"""Initialize an object by identifying it by its binary sha.
diff --git a/git/objects/blob.py b/git/objects/blob.py
index 017178f0..99b5c636 100644
--- a/git/objects/blob.py
+++ b/git/objects/blob.py
@@ -6,6 +6,8 @@
from mimetypes import guess_type
from . import base
+from git.types import Literal
+
__all__ = ('Blob', )
@@ -13,7 +15,7 @@ class Blob(base.IndexObject):
"""A Blob encapsulates a git blob object"""
DEFAULT_MIME_TYPE = "text/plain"
- type = "blob"
+ type: Literal['blob'] = "blob"
# valid blob modes
executable_mode = 0o100755
diff --git a/git/objects/commit.py b/git/objects/commit.py
index 65a87591..11cf52a5 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -41,10 +41,11 @@ import logging
from typing import Any, IO, Iterator, List, Sequence, Tuple, Union, TYPE_CHECKING
-from git.types import PathLike, TypeGuard
+from git.types import PathLike, TypeGuard, Literal
if TYPE_CHECKING:
from git.repo import Repo
+ from git.refs import SymbolicReference
# ------------------------------------------------------------------------
@@ -73,14 +74,14 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
default_encoding = "UTF-8"
# object configuration
- type = "commit"
+ type: Literal['commit'] = "commit"
__slots__ = ("tree",
"author", "authored_date", "author_tz_offset",
"committer", "committed_date", "committer_tz_offset",
"message", "parents", "encoding", "gpgsig")
_id_attribute_ = "hexsha"
- def __init__(self, repo: 'Repo', binsha: bytes, tree: Union['Tree', None] = None,
+ def __init__(self, repo: 'Repo', binsha: bytes, tree: Union[Tree, None] = None,
author: Union[Actor, None] = None,
authored_date: Union[int, None] = None,
author_tz_offset: Union[None, float] = None,
@@ -201,11 +202,11 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
# END handle attrs
@property
- def authored_datetime(self) -> 'datetime.datetime':
+ def authored_datetime(self) -> datetime.datetime:
return from_timestamp(self.authored_date, self.author_tz_offset)
@property
- def committed_datetime(self) -> 'datetime.datetime':
+ def committed_datetime(self) -> datetime.datetime:
return from_timestamp(self.committed_date, self.committer_tz_offset)
@property
@@ -242,7 +243,7 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
return self.repo.git.name_rev(self)
@classmethod
- def iter_items(cls, repo: 'Repo', rev: str, # type: ignore
+ def iter_items(cls, repo: 'Repo', rev: Union[str, 'Commit', 'SymbolicReference'], # type: ignore
paths: Union[PathLike, Sequence[PathLike]] = '', **kwargs: Any
) -> Iterator['Commit']:
"""Find all commits matching the given criteria.
@@ -354,7 +355,7 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
finalize_process(proc_or_stream)
@ classmethod
- def create_from_tree(cls, repo: 'Repo', tree: Union['Tree', str], message: str,
+ 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):
@@ -516,8 +517,10 @@ class Commit(base.Object, TraversableIterableObj, Diffable, Serializable):
return self
def _deserialize(self, stream: BytesIO) -> 'Commit':
- """:param from_rev_list: if true, the stream format is coming from the rev-list command
- Otherwise it is assumed to be a plain data stream from our object"""
+ """
+ :param from_rev_list: if true, the stream format is coming from the rev-list command
+ Otherwise it is assumed to be a plain data stream from our object
+ """
readline = stream.readline
self.tree = Tree(self.repo, hex_to_bin(readline().split()[1]), Tree.tree_id << 12, '')
diff --git a/git/objects/fun.py b/git/objects/fun.py
index fc2ea1e7..d6cdafe1 100644
--- a/git/objects/fun.py
+++ b/git/objects/fun.py
@@ -167,7 +167,7 @@ def traverse_trees_recursive(odb: 'GitCmdObjectDB', tree_shas: Sequence[Union[by
data: List[EntryTupOrNone] = []
else:
# make new list for typing as list invariant
- data = [x for x in tree_entries_from_data(odb.stream(tree_sha).read())]
+ data = list(tree_entries_from_data(odb.stream(tree_sha).read()))
# END handle muted trees
trees_data.append(data)
# END for each sha to get data for
diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py
index b485dbf6..21cfcd5a 100644
--- a/git/objects/submodule/base.py
+++ b/git/objects/submodule/base.py
@@ -52,7 +52,7 @@ from .util import (
from typing import Callable, Dict, Mapping, Sequence, TYPE_CHECKING, cast
from typing import Any, Iterator, Union
-from git.types import Commit_ish, PathLike, TBD
+from git.types import Commit_ish, Literal, PathLike, TBD
if TYPE_CHECKING:
from git.index import IndexFile
@@ -105,7 +105,7 @@ class Submodule(IndexObject, TraversableIterableObj):
k_default_mode = stat.S_IFDIR | stat.S_IFLNK # submodules are directories with link-status
# this is a bogus type for base class compatibility
- type = 'submodule'
+ type: Literal['submodule'] = 'submodule' # type: ignore
__slots__ = ('_parent_commit', '_url', '_branch_path', '_name', '__weakref__')
_cache_attrs = ('path', '_url', '_branch_path')
diff --git a/git/objects/tag.py b/git/objects/tag.py
index cb6efbe9..4a2fcb0d 100644
--- a/git/objects/tag.py
+++ b/git/objects/tag.py
@@ -11,6 +11,8 @@ from ..compat import defenc
from typing import List, TYPE_CHECKING, Union
+from git.types import Literal
+
if TYPE_CHECKING:
from git.repo import Repo
from git.util import Actor
@@ -24,7 +26,7 @@ __all__ = ("TagObject", )
class TagObject(base.Object):
"""Non-Lightweight tag carrying additional information about an object we are pointing to."""
- type = "tag"
+ type: Literal['tag'] = "tag"
__slots__ = ("object", "tag", "tagger", "tagged_date", "tagger_tz_offset", "message")
def __init__(self, repo: 'Repo', binsha: bytes,
diff --git a/git/objects/tree.py b/git/objects/tree.py
index a9656c1d..0e3f44b9 100644
--- a/git/objects/tree.py
+++ b/git/objects/tree.py
@@ -24,7 +24,7 @@ from .fun import (
from typing import (Any, Callable, Dict, Iterable, Iterator, List,
Tuple, Type, Union, cast, TYPE_CHECKING)
-from git.types import PathLike, TypeGuard
+from git.types import PathLike, TypeGuard, Literal
if TYPE_CHECKING:
from git.repo import Repo
@@ -195,7 +195,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
blob = tree[0]
"""
- type = "tree"
+ type: Literal['tree'] = "tree"
__slots__ = "_cache"
# actual integer ids for comparison
@@ -285,7 +285,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
return [i for i in self if i.type == "tree"]
@ property
- def blobs(self) -> List['Blob']:
+ def blobs(self) -> List[Blob]:
""":return: list(Blob, ...) list of blobs directly below this tree"""
return [i for i in self if i.type == "blob"]
@@ -322,8 +322,8 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
# assert is_tree_traversed(ret_tup), f"Type is {[type(x) for x in list(ret_tup[0])]}"
# return ret_tup[0]"""
return cast(Union[Iterator[IndexObjUnion], Iterator[TraversedTreeTup]],
- super(Tree, self).traverse(predicate, prune, depth, # type: ignore
- branch_first, visit_once, ignore_self))
+ super(Tree, self)._traverse(predicate, prune, depth, # type: ignore
+ branch_first, visit_once, ignore_self))
def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[IndexObjUnion]:
"""
@@ -331,7 +331,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable):
traverse()
Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']]
"""
- return super(Tree, self).list_traverse(* args, **kwargs)
+ return super(Tree, self)._list_traverse(* args, **kwargs)
# List protocol