diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-05-18 07:43:53 +0800 |
---|---|---|
committer | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-05-18 07:43:53 +0800 |
commit | 21ec529987d10e0010badd37f8da3274167d436f (patch) | |
tree | a3394cfe902ce7edd07c89420c21c13274a2d295 /git/objects/base.py | |
parent | b30720ee4d9762a03eae4fa7cfa4b0190d81784d (diff) | |
download | gitpython-21ec529987d10e0010badd37f8da3274167d436f.tar.gz |
Run everything through 'black'
That way people who use it won't be deterred, while it unifies style
everywhere.
Diffstat (limited to 'git/objects/base.py')
-rw-r--r-- | git/objects/base.py | 61 |
1 files changed, 38 insertions, 23 deletions
diff --git a/git/objects/base.py b/git/objects/base.py index 66e15a8f..9d005725 100644 --- a/git/objects/base.py +++ b/git/objects/base.py @@ -27,7 +27,7 @@ if TYPE_CHECKING: from .submodule.base import Submodule from git.refs.reference import Reference -IndexObjUnion = Union['Tree', 'Blob', 'Submodule'] +IndexObjUnion = Union["Tree", "Blob", "Submodule"] # -------------------------------------------------------------------------- @@ -40,14 +40,20 @@ __all__ = ("Object", "IndexObject") class Object(LazyMixin): """Implements an Object which may be Blobs, Trees, Commits and Tags""" - NULL_HEX_SHA = '0' * 40 - NULL_BIN_SHA = b'\0' * 20 - TYPES = (dbtyp.str_blob_type, dbtyp.str_tree_type, dbtyp.str_commit_type, dbtyp.str_tag_type) + NULL_HEX_SHA = "0" * 40 + NULL_BIN_SHA = b"\0" * 20 + + TYPES = ( + dbtyp.str_blob_type, + dbtyp.str_tree_type, + dbtyp.str_commit_type, + dbtyp.str_tag_type, + ) __slots__ = ("repo", "binsha", "size") type: Union[Lit_commit_ish, None] = None - def __init__(self, repo: 'Repo', binsha: bytes): + def __init__(self, repo: "Repo", binsha: bytes): """Initialize an object by identifying it by its binary sha. All keyword arguments will be set on demand if None. @@ -57,10 +63,13 @@ class Object(LazyMixin): super(Object, self).__init__() self.repo = repo self.binsha = binsha - assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % (binsha, len(binsha)) + assert len(binsha) == 20, "Require 20 byte binary sha, got %r, len = %i" % ( + binsha, + len(binsha), + ) @classmethod - def new(cls, repo: 'Repo', id: Union[str, 'Reference']) -> Commit_ish: + 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 @@ -73,14 +82,14 @@ class Object(LazyMixin): return repo.rev_parse(str(id)) @classmethod - def new_from_sha(cls, repo: 'Repo', sha1: bytes) -> Commit_ish: + def new_from_sha(cls, repo: "Repo", sha1: bytes) -> Commit_ish: """ :return: new object instance of a type appropriate to represent the given binary sha1 :param sha1: 20 byte binary sha1""" if sha1 == cls.NULL_BIN_SHA: # the NULL binsha is always the root commit - return get_object_type_by_name(b'commit')(repo, sha1) + return get_object_type_by_name(b"commit")(repo, sha1) # END handle special case oinfo = repo.odb.info(sha1) inst = get_object_type_by_name(oinfo.type)(repo, oinfo.binsha) @@ -98,13 +107,13 @@ class Object(LazyMixin): def __eq__(self, other: Any) -> bool: """:return: True if the objects have the same SHA1""" - if not hasattr(other, 'binsha'): + if not hasattr(other, "binsha"): return False return self.binsha == other.binsha def __ne__(self, other: Any) -> bool: - """:return: True if the objects do not have the same SHA1 """ - if not hasattr(other, 'binsha'): + """:return: True if the objects do not have the same SHA1""" + if not hasattr(other, "binsha"): return True return self.binsha != other.binsha @@ -124,15 +133,15 @@ class Object(LazyMixin): def hexsha(self) -> str: """:return: 40 byte hex version of our 20 byte binary sha""" # b2a_hex produces bytes - return bin_to_hex(self.binsha).decode('ascii') + return bin_to_hex(self.binsha).decode("ascii") @property - def data_stream(self) -> 'OStream': - """ :return: File Object compatible stream to the uncompressed raw data of the object + def data_stream(self) -> "OStream": + """:return: File Object compatible stream to the uncompressed raw data of the object :note: returned streams must be read in order""" return self.repo.odb.stream(self.binsha) - def stream_data(self, ostream: 'OStream') -> 'Object': + def stream_data(self, ostream: "OStream") -> "Object": """Writes our data directly to the given output stream :param ostream: File object compatible stream object. :return: self""" @@ -145,14 +154,19 @@ class IndexObject(Object): """Base for all objects that can be part of the index file , namely Tree, Blob and SubModule objects""" + __slots__ = ("path", "mode") # for compatibility with iterable lists - _id_attribute_ = 'path' - - def __init__(self, - repo: 'Repo', binsha: bytes, mode: Union[None, int] = None, path: Union[None, PathLike] = None - ) -> None: + _id_attribute_ = "path" + + def __init__( + self, + repo: "Repo", + binsha: bytes, + mode: Union[None, int] = None, + path: Union[None, PathLike] = None, + ) -> None: """Initialize a newly instanced IndexObject :param repo: is the Repo we are located in @@ -184,7 +198,8 @@ class IndexObject(Object): # they cannot be retrieved lateron ( not without searching for them ) raise AttributeError( "Attribute '%s' unset: path and mode attributes must have been set during %s object creation" - % (attr, type(self).__name__)) + % (attr, type(self).__name__) + ) else: super(IndexObject, self)._set_cache_(attr) # END handle slot attribute @@ -201,7 +216,7 @@ class IndexObject(Object): Absolute path to this index object in the file system ( as opposed to the .path field which is a path relative to the git repository ). - The returned path will be native to the system and contains '\' on windows. """ + The returned path will be native to the system and contains '\' on windows.""" if self.repo.working_tree_dir is not None: return join_path_native(self.repo.working_tree_dir, self.path) else: |