Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit191f4cf

Browse files
committed
Fix some annotations in git.repo.fun
1 parent7328a00 commit191f4cf

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

‎git/repo/fun.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,30 @@
66
from __future__importannotations
77

88
importos
9-
importstat
9+
importos.pathasosp
1010
frompathlibimportPath
11+
importstat
1112
fromstringimportdigits
1213

14+
fromgit.cmdimportGit
1315
fromgit.excimportWorkTreeRepositoryUnsupported
1416
fromgit.objectsimportObject
1517
fromgit.refsimportSymbolicReference
1618
fromgit.utilimporthex_to_bin,bin_to_hex,cygpath
17-
fromgitdb.excimport (
18-
BadObject,
19-
BadName,
20-
)
21-
22-
importos.pathasosp
23-
fromgit.cmdimportGit
19+
fromgitdb.excimportBadName,BadObject
2420

2521
# Typing ----------------------------------------------------------------------
2622

27-
fromtypingimportUnion,Optional,cast,TYPE_CHECKING
28-
fromgit.typesimportOld_commit_ish
23+
fromtypingimportOptional,TYPE_CHECKING,Union,cast,overload
24+
25+
fromgit.typesimportAnyGitObject,Literal,Old_commit_ish,PathLike
2926

3027
ifTYPE_CHECKING:
31-
fromgit.typesimportPathLike
32-
from .baseimportRepo
3328
fromgit.dbimportGitCmdObjectDB
34-
fromgit.refs.referenceimportReference
3529
fromgit.objectsimportCommit,TagObject,Blob,Tree
30+
fromgit.refs.referenceimportReference
3631
fromgit.refs.tagimportTag
32+
from .baseimportRepo
3733

3834
# ----------------------------------------------------------------------------
3935

@@ -56,7 +52,7 @@ def touch(filename: str) -> str:
5652
returnfilename
5753

5854

59-
defis_git_dir(d:"PathLike")->bool:
55+
defis_git_dir(d:PathLike)->bool:
6056
"""This is taken from the git setup.c:is_git_directory function.
6157
6258
:raise git.exc.WorkTreeRepositoryUnsupported:
@@ -79,7 +75,7 @@ def is_git_dir(d: "PathLike") -> bool:
7975
returnFalse
8076

8177

82-
deffind_worktree_git_dir(dotgit:"PathLike")->Optional[str]:
78+
deffind_worktree_git_dir(dotgit:PathLike)->Optional[str]:
8379
"""Search for a gitdir for this worktree."""
8480
try:
8581
statbuf=os.stat(dotgit)
@@ -98,7 +94,7 @@ def find_worktree_git_dir(dotgit: "PathLike") -> Optional[str]:
9894
returnNone
9995

10096

101-
deffind_submodule_git_dir(d:"PathLike")->Optional["PathLike"]:
97+
deffind_submodule_git_dir(d:PathLike)->Optional[PathLike]:
10298
"""Search for a submodule repo."""
10399
ifis_git_dir(d):
104100
returnd
@@ -141,18 +137,26 @@ def short_to_long(odb: "GitCmdObjectDB", hexsha: str) -> Optional[bytes]:
141137
# END exception handling
142138

143139

144-
defname_to_object(
145-
repo:"Repo",name:str,return_ref:bool=False
146-
)->Union[SymbolicReference,"Commit","TagObject","Blob","Tree"]:
140+
@overload
141+
defname_to_object(repo:"Repo",name:str,return_ref:Literal[False]= ...)->AnyGitObject:
142+
...
143+
144+
145+
@overload
146+
defname_to_object(repo:"Repo",name:str,return_ref:Literal[True])->Union[AnyGitObject,SymbolicReference]:
147+
...
148+
149+
150+
defname_to_object(repo:"Repo",name:str,return_ref:bool=False)->Union[AnyGitObject,SymbolicReference]:
147151
"""
148152
:return:
149153
Object specified by the given name - hexshas (short and long) as well as
150154
references are supported.
151155
152156
:param return_ref:
153157
If ``True``, and name specifies a reference, we will return the reference
154-
instead of the object. Otherwise it will raise `~gitdb.exc.BadObject` or
155-
`~gitdb.exc.BadName`.
158+
instead of the object. Otherwise it will raise:class:`~gitdb.exc.BadObject` or
159+
:class:`~gitdb.exc.BadName`.
156160
"""
157161
hexsha:Union[None,str,bytes]=None
158162

@@ -201,7 +205,7 @@ def name_to_object(
201205
returnObject.new_from_sha(repo,hex_to_bin(hexsha))
202206

203207

204-
defderef_tag(tag:"Tag")->"TagObject":
208+
defderef_tag(tag:"Tag")->AnyGitObject:
205209
"""Recursively dereference a tag and return the resulting object."""
206210
whileTrue:
207211
try:
@@ -212,7 +216,7 @@ def deref_tag(tag: "Tag") -> "TagObject":
212216
returntag
213217

214218

215-
defto_commit(obj:Object)->Union["Commit","TagObject"]:
219+
defto_commit(obj:Object)->"Commit":
216220
"""Convert the given object to a commit if possible and return it."""
217221
ifobj.type=="tag":
218222
obj=deref_tag(obj)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp