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

Commit8fc25c6

Browse files
committed
Add types to refs/head.py
1 parentae13c6d commit8fc25c6

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

‎git/refs/head.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
55
from .symbolicimportSymbolicReference
66
from .referenceimportReference
77

8-
fromtypingimportUnion,TYPE_CHECKING
8+
# typinng ---------------------------------------------------
99

10-
fromgit.typesimportCommit_ish
10+
fromtypingimportAny,Sequence,Union,TYPE_CHECKING
11+
12+
fromgit.typesimportPathLike,Commit_ish
1113

1214
ifTYPE_CHECKING:
1315
fromgit.repoimportRepo
16+
fromgit.objectsimportCommit
17+
fromgit.refsimportRemoteReference
18+
19+
# -------------------------------------------------------------------
1420

1521
__all__= ["HEAD","Head"]
1622

@@ -29,20 +35,21 @@ class HEAD(SymbolicReference):
2935
_ORIG_HEAD_NAME='ORIG_HEAD'
3036
__slots__= ()
3137

32-
def__init__(self,repo:'Repo',path=_HEAD_NAME):
38+
def__init__(self,repo:'Repo',path:PathLike=_HEAD_NAME):
3339
ifpath!=self._HEAD_NAME:
3440
raiseValueError("HEAD instance must point to %r, got %r"% (self._HEAD_NAME,path))
3541
super(HEAD,self).__init__(repo,path)
36-
self.commit:'Commit_ish'
42+
self.commit:'Commit'
3743

38-
deforig_head(self)->'SymbolicReference':
44+
deforig_head(self)->SymbolicReference:
3945
"""
4046
:return: SymbolicReference pointing at the ORIG_HEAD, which is maintained
4147
to contain the previous value of HEAD"""
4248
returnSymbolicReference(self.repo,self._ORIG_HEAD_NAME)
4349

44-
defreset(self,commit:Union[Commit_ish,SymbolicReference,str]='HEAD',index=True,working_tree=False,
45-
paths=None,**kwargs):
50+
defreset(self,commit:Union[Commit_ish,SymbolicReference,str]='HEAD',
51+
index:bool=True,working_tree:bool=False,
52+
paths:Union[PathLike,Sequence[PathLike],None]=None,**kwargs:Any)->'HEAD':
4653
"""Reset our HEAD to the given commit optionally synchronizing
4754
the index and working tree. The reference we refer to will be set to
4855
commit as well.
@@ -122,7 +129,7 @@ class Head(Reference):
122129
k_config_remote_ref="merge"# branch to merge from remote
123130

124131
@classmethod
125-
defdelete(cls,repo,*heads,**kwargs):
132+
defdelete(cls,repo:'Repo',*heads:'Head',**kwargs:Any):
126133
"""Delete the given heads
127134
128135
:param force:
@@ -135,7 +142,7 @@ def delete(cls, repo, *heads, **kwargs):
135142
flag="-D"
136143
repo.git.branch(flag,*heads)
137144

138-
defset_tracking_branch(self,remote_reference):
145+
defset_tracking_branch(self,remote_reference:'RemoteReference')->'Head':
139146
"""
140147
Configure this branch to track the given remote reference. This will alter
141148
this branch's configuration accordingly.
@@ -160,7 +167,7 @@ def set_tracking_branch(self, remote_reference):
160167

161168
returnself
162169

163-
deftracking_branch(self):
170+
deftracking_branch(self)->Union['RemoteReference',None]:
164171
"""
165172
:return: The remote_reference we are tracking, or None if we are
166173
not a tracking branch"""
@@ -175,7 +182,7 @@ def tracking_branch(self):
175182
# we are not a tracking branch
176183
returnNone
177184

178-
defrename(self,new_path,force=False):
185+
defrename(self,new_path:PathLike,force:bool=False)->'Head':
179186
"""Rename self to a new path
180187
181188
:param new_path:
@@ -196,7 +203,7 @@ def rename(self, new_path, force=False):
196203
self.path="%s/%s"% (self._common_path_default,new_path)
197204
returnself
198205

199-
defcheckout(self,force=False,**kwargs):
206+
defcheckout(self,force:bool=False,**kwargs:Any):
200207
"""Checkout this head by setting the HEAD to this reference, by updating the index
201208
to reflect the tree we point to and by updating the working tree to reflect
202209
the latest index.
@@ -231,7 +238,7 @@ def checkout(self, force=False, **kwargs):
231238
returnself.repo.active_branch
232239

233240
#{ Configuration
234-
def_config_parser(self,read_only):
241+
def_config_parser(self,read_only:bool)->SectionConstraint:
235242
ifread_only:
236243
parser=self.repo.config_reader()
237244
else:
@@ -240,13 +247,13 @@ def _config_parser(self, read_only):
240247

241248
returnSectionConstraint(parser,'branch "%s"'%self.name)
242249

243-
defconfig_reader(self):
250+
defconfig_reader(self)->SectionConstraint:
244251
"""
245252
:return: A configuration parser instance constrained to only read
246253
this instance's values"""
247254
returnself._config_parser(read_only=True)
248255

249-
defconfig_writer(self):
256+
defconfig_writer(self)->SectionConstraint:
250257
"""
251258
:return: A configuration writer instance with read-and write access
252259
to options of this head"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp