| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,9 +15,9 @@ | |||
| 15 | 15 | ||
| 16 | 16 | # typing ------------------------------------------------------------------ | |
| 17 | 17 | ||
| 18 | - from typing import Any, TYPE_CHECKING, Optional, Union | ||
| 18 | + from typing import Any, TYPE_CHECKING, Union | ||
| 19 | 19 | ||
| 20 | - from git.types import PathLike, Commit_ish | ||
| 20 | + from git.types import PathLike, Commit_ish, Lit_commit_ish | ||
| 21 | 21 | ||
| 22 | 22 | if TYPE_CHECKING: | |
| 23 | 23 | from git.repo import Repo | |
@@ -44,7 +44,7 @@ class Object(LazyMixin): | |||
| 44 | 44 | ||
| 45 | 45 | TYPES = (dbtyp.str_blob_type, dbtyp.str_tree_type, dbtyp.str_commit_type, dbtyp.str_tag_type) | |
| 46 | 46 | __slots__ = ("repo", "binsha", "size") | |
| 47 | - type = None # type: Optional[str] # to be set by subclass | ||
| 47 | + type: Union[Lit_commit_ish, None] = None | ||
| 48 | 48 | ||
| 49 | 49 | def __init__(self, repo: 'Repo', binsha: bytes): | |
| 50 | 50 | """Initialize an object by identifying it by its binary sha. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,14 +6,16 @@ | |||
| 6 | 6 | from mimetypes import guess_type | |
| 7 | 7 | from . import base | |
| 8 | 8 | ||
| 9 | + from git.types import Literal | ||
| 10 | + | ||
| 9 | 11 | __all__ = ('Blob', ) | |
| 10 | 12 | ||
| 11 | 13 | ||
| 12 | 14 | class Blob(base.IndexObject): | |
| 13 | 15 | ||
| 14 | 16 | """A Blob encapsulates a git blob object""" | |
| 15 | 17 | DEFAULT_MIME_TYPE = "text/plain" | |
| 16 | - type = "blob" | ||
| 18 | + type: Literal['blob'] = "blob" | ||
| 17 | 19 | ||
| 18 | 20 | # valid blob modes | |
| 19 | 21 | executable_mode = 0o100755 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,10 +41,11 @@ | |||
| 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 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -167,7 +167,7 @@ def traverse_trees_recursive(odb: 'GitCmdObjectDB', tree_shas: Sequence[Union[by | |||
| 167 | 167 | data: List[EntryTupOrNone] = [] | |
| 168 | 168 | else: | |
| 169 | 169 | # make new list for typing as list invariant | |
| 170 | - data = [x for x in tree_entries_from_data(odb.stream(tree_sha).read())] | ||
| 170 | + data = list(tree_entries_from_data(odb.stream(tree_sha).read())) | ||
| 171 | 171 | # END handle muted trees | |
| 172 | 172 | trees_data.append(data) | |
| 173 | 173 | # END for each sha to get data for | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,7 +52,7 @@ | |||
| 52 | 52 | from typing import Callable, Dict, Mapping, Sequence, TYPE_CHECKING, cast | |
| 53 | 53 | from typing import Any, Iterator, Union | |
| 54 | 54 | ||
| 55 | - from git.types import Commit_ish, PathLike, TBD | ||
| 55 | + from git.types import Commit_ish, Literal, PathLike, TBD | ||
| 56 | 56 | ||
| 57 | 57 | if TYPE_CHECKING: | |
| 58 | 58 | from git.index import IndexFile | |
@@ -105,7 +105,7 @@ class Submodule(IndexObject, TraversableIterableObj): | |||
| 105 | 105 | k_default_mode = stat.S_IFDIR | stat.S_IFLNK # submodules are directories with link-status | |
| 106 | 106 | ||
| 107 | 107 | # this is a bogus type for base class compatibility | |
| 108 | - type = 'submodule' | ||
| 108 | + type: Literal['submodule'] = 'submodule' # type: ignore | ||
| 109 | 109 | ||
| 110 | 110 | __slots__ = ('_parent_commit', '_url', '_branch_path', '_name', '__weakref__') | |
| 111 | 111 | _cache_attrs = ('path', '_url', '_branch_path') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,6 +11,8 @@ | |||
| 11 | 11 | ||
| 12 | 12 | from typing import List, TYPE_CHECKING, Union | |
| 13 | 13 | ||
| 14 | + from git.types import Literal | ||
| 15 | + | ||
| 14 | 16 | if TYPE_CHECKING: | |
| 15 | 17 | from git.repo import Repo | |
| 16 | 18 | from git.util import Actor | |
@@ -24,7 +26,7 @@ | |||
| 24 | 26 | class TagObject(base.Object): | |
| 25 | 27 | ||
| 26 | 28 | """Non-Lightweight tag carrying additional information about an object we are pointing to.""" | |
| 27 | - type = "tag" | ||
| 29 | + type: Literal['tag'] = "tag" | ||
| 28 | 30 | __slots__ = ("object", "tag", "tagger", "tagged_date", "tagger_tz_offset", "message") | |
| 29 | 31 | ||
| 30 | 32 | def __init__(self, repo: 'Repo', binsha: bytes, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,7 @@ | |||
| 24 | 24 | from typing import (Any, Callable, Dict, Iterable, Iterator, List, | |
| 25 | 25 | Tuple, Type, Union, cast, TYPE_CHECKING) | |
| 26 | 26 | ||
| 27 | - from git.types import PathLike, TypeGuard | ||
| 27 | + from git.types import PathLike, TypeGuard, Literal | ||
| 28 | 28 | ||
| 29 | 29 | if TYPE_CHECKING: | |
| 30 | 30 | from git.repo import Repo | |
@@ -195,7 +195,7 @@ class Tree(IndexObject, git_diff.Diffable, util.Traversable, util.Serializable): | |||
| 195 | 195 | blob = tree[0] | |
| 196 | 196 | """ | |
| 197 | 197 | ||
| 198 | - type = "tree" | ||
| 198 | + type: Literal['tree'] = "tree" | ||
| 199 | 199 | __slots__ = "_cache" | |
| 200 | 200 | ||
| 201 | 201 | # actual integer ids for comparison | |
@@ -285,7 +285,7 @@ def trees(self) -> List['Tree']: | |||
| 285 | 285 | return [i for i in self if i.type == "tree"] | |
| 286 | 286 | ||
| 287 | 287 | @ property | |
| 288 | - def blobs(self) -> List['Blob']: | ||
| 288 | + def blobs(self) -> List[Blob]: | ||
| 289 | 289 | """:return: list(Blob, ...) list of blobs directly below this tree""" | |
| 290 | 290 | return [i for i in self if i.type == "blob"] | |
| 291 | 291 | ||
@@ -322,16 +322,16 @@ def traverse(self, # type: ignore # overrides super() | |||
| 322 | 322 | # assert is_tree_traversed(ret_tup), f"Type is {[type(x) for x in list(ret_tup[0])]}" | |
| 323 | 323 | # return ret_tup[0]""" | |
| 324 | 324 | return cast(Union[Iterator[IndexObjUnion], Iterator[TraversedTreeTup]], | |
| 325 | - super(Tree, self).traverse(predicate, prune, depth, # type: ignore | ||
| 326 | - branch_first, visit_once, ignore_self)) | ||
| 325 | + super(Tree, self)._traverse(predicate, prune, depth, # type: ignore | ||
| 326 | + branch_first, visit_once, ignore_self)) | ||
| 327 | 327 | ||
| 328 | 328 | def list_traverse(self, *args: Any, **kwargs: Any) -> IterableList[IndexObjUnion]: | |
| 329 | 329 | """ | |
| 330 | 330 | :return: IterableList with the results of the traversal as produced by | |
| 331 | 331 | traverse() | |
| 332 | 332 | Tree -> IterableList[Union['Submodule', 'Tree', 'Blob']] | |
| 333 | 333 | """ | |
| 334 | - return super(Tree, self).list_traverse(* args, **kwargs) | ||
| 334 | + return super(Tree, self)._list_traverse(* args, **kwargs) | ||
| 335 | 335 | ||
| 336 | 336 | # List protocol | |
| 337 | 337 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments