Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1fe4dc8

Browse files
committed
Define GitObjectTypeString and update Object to use it
This is equivalent to the old Lit_commit_ish union; it is the type of a literal string that has one of the four values that represent actual git object types. The old Lit_commit_ish union was only used in one place in GitPython: to annotate Object.type. This replaces that and updates its docstring, as well as the Object class docstring. (One change in the Object class docstring--adding a mention of the RootModule subclass of Submodule--is not conceptually related to these other changes.)
1 parent 787f65c commit 1fe4dc8

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

git/objects/base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from typing import Any, TYPE_CHECKING, Union
1818

19-
from git.types import PathLike, Old_commit_ish, Lit_old_commit_ish
19+
from git.types import GitObjectTypeString, Old_commit_ish, PathLike
2020

2121
if TYPE_CHECKING:
2222
from git.repo import Repo
@@ -36,7 +36,7 @@
3636
class Object(LazyMixin):
3737
"""Base class for classes representing git object types.
3838
39-
The following leaf classes represent specific kinds of git objects:
39+
The following four leaf classes represent specific kinds of git objects:
4040
4141
* :class:`Blob <git.objects.blob.Blob>`
4242
* :class:`Tree <git.objects.tree.Tree>`
@@ -53,12 +53,14 @@ class Object(LazyMixin):
5353
* "tag object": https://git-scm.com/docs/gitglossary#def_tag_object
5454
5555
:note:
56-
See the :class:`~git.types.Old_commit_ish` union type.
56+
See the :class:`~git.types.AnyGitObject` union type of the four leaf subclasses
57+
that represent actual git object types.
5758
5859
:note:
5960
:class:`~git.objects.submodule.base.Submodule` is defined under the hierarchy
6061
rooted at this :class:`Object` class, even though submodules are not really a
61-
type of git object.
62+
type of git object. (This also applies to its
63+
:class:`~git.objects.submodule.root.RootModule` subclass.)
6264
6365
:note:
6466
This :class:`Object` class should not be confused with :class:`object` (the root
@@ -77,7 +79,7 @@ class Object(LazyMixin):
7779

7880
__slots__ = ("repo", "binsha", "size")
7981

80-
type: Union[Lit_old_commit_ish, None] = None
82+
type: Union[GitObjectTypeString, None] = None
8183
"""String identifying (a concrete :class:`Object` subtype for) a git object type.
8284
8385
The subtypes that this may name correspond to the kinds of git objects that exist,
@@ -90,7 +92,7 @@ class Object(LazyMixin):
9092
``None`` in concrete leaf subclasses representing specific git object types.
9193
9294
:note:
93-
See also :class:`~git.types.Old_commit_ish`.
95+
See also :class:`~git.types.GitObjectTypeString`.
9496
"""
9597

9698
def __init__(self, repo: "Repo", binsha: bytes):

git/types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@
114114
object types.
115115
"""
116116

117+
GitObjectTypeString = Literal["commit", "tag", "blob", "tree"]
118+
"""Literal strings identifying git object types and the
119+
:class:`~git.objects.base.Object`-based types that represent them.
120+
121+
See the :attr:`Object.type <git.objects.base.Object.type>` attribute. These are its
122+
values in :class:`~git.objects.base.Object` subclasses that represent git objects. These
123+
literals therefore correspond to the types in the :class:`AnyGitObject` union.
124+
125+
These are the same strings git itself uses to identify its four object types. See
126+
gitglossary(7) on "object type": https://git-scm.com/docs/gitglossary#def_object_type
127+
"""
128+
117129
# FIXME: Replace uses with AnyGitObject and Commit_ish, and remove this.
118130
Old_commit_ish = Union["Commit", "TagObject", "Blob", "Tree"]
119131
"""Union of the :class:`~git.objects.base.Object`-based types that represent git object
@@ -140,6 +152,8 @@
140152
compatibility.
141153
"""
142154

155+
# FIXME: After replacing the one use with GitObjectTypeString, define Lit_commit_ish
156+
# somehow (it is a breaking change to remove it entirely). Maybe deprecate it.
143157
Lit_old_commit_ish = Literal["commit", "tag", "blob", "tree"]
144158
"""Literal strings identifying concrete :class:`~git.objects.base.Object` subtypes
145159
representing git object types.

0 commit comments

Comments
 (0)