2222
2323from typing import Optional ,TYPE_CHECKING ,Union ,cast ,overload
2424
25- from git .types import AnyGitObject ,Literal ,Old_commit_ish , PathLike
25+ from git .types import AnyGitObject ,Literal ,PathLike
2626
2727if TYPE_CHECKING :
2828from git .db import GitCmdObjectDB
29- from git .objects import Commit ,TagObject , Blob , Tree
29+ from git .objects import Commit ,TagObject
3030from git .refs .reference import Reference
3131from git .refs .tag import Tag
3232from .base import Repo
@@ -227,12 +227,18 @@ def to_commit(obj: Object) -> "Commit":
227227return obj
228228
229229
230- def rev_parse (repo :"Repo" ,rev :str )-> Union ["Commit" ,"Tag" ,"Tree" ,"Blob" ]:
231- """
230+ def rev_parse (repo :"Repo" ,rev :str )-> AnyGitObject :
231+ """Parse a revision string. Like ``git rev-parse``.
232+
232233 :return:
233- `~git.objects.base.Object` at the given revision, either
234- `~git.objects.commit.Commit`, `~git.refs.tag.Tag`, `~git.objects.tree.Tree` or
235- `~git.objects.blob.Blob`.
234+ `~git.objects.base.Object` at the given revision.
235+
236+ This may be any type of git object:
237+
238+ * :class:`Commit <git.objects.commit.Commit>`
239+ * :class:`TagObject <git.objects.tag.TagObject>`
240+ * :class:`Tree <git.objects.tree.Tree>`
241+ * :class:`Blob <git.objects.blob.Blob>`
236242
237243 :param rev:
238244 ``git rev-parse``-compatible revision specification as string. Please see
@@ -253,7 +259,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
253259raise NotImplementedError ("commit by message search (regex)" )
254260# END handle search
255261
256- obj :Union [ Old_commit_ish , "Reference" , None ]= None
262+ obj :Optional [ AnyGitObject ]= None
257263ref = None
258264output_type = "commit"
259265start = 0
@@ -275,12 +281,10 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
275281if token == "@" :
276282ref = cast ("Reference" ,name_to_object (repo ,rev [:start ],return_ref = True ))
277283else :
278- obj = cast ( Old_commit_ish , name_to_object (repo ,rev [:start ]) )
284+ obj = name_to_object (repo ,rev [:start ])
279285# END handle token
280286# END handle refname
281287else :
282- assert obj is not None
283-
284288if ref is not None :
285289obj = cast ("Commit" ,ref .commit )
286290# END handle ref
@@ -300,7 +304,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
300304pass # Default.
301305elif output_type == "tree" :
302306try :
303- obj = cast (Old_commit_ish ,obj )
307+ obj = cast (AnyGitObject ,obj )
304308obj = to_commit (obj ).tree
305309except (AttributeError ,ValueError ):
306310pass # Error raised later.
@@ -373,7 +377,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
373377parsed_to = start
374378# Handle hierarchy walk.
375379try :
376- obj = cast (Old_commit_ish ,obj )
380+ obj = cast (AnyGitObject ,obj )
377381if token == "~" :
378382obj = to_commit (obj )
379383for _ in range (num ):
@@ -402,7 +406,7 @@ def rev_parse(repo: "Repo", rev: str) -> Union["Commit", "Tag", "Tree", "Blob"]:
402406
403407# Still no obj? It's probably a simple name.
404408if obj is None :
405- obj = cast ( Old_commit_ish , name_to_object (repo ,rev ) )
409+ obj = name_to_object (repo ,rev )
406410parsed_to = lr
407411# END handle simple name
408412