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

Commitadc00dd

Browse files
committed
Fix more missing types in Symbolic.py, cos GuthubActions pytest stuck
1 parent070f5c0 commitadc00dd

File tree

6 files changed

+47
-27
lines changed

6 files changed

+47
-27
lines changed

‎git/objects/commit.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def __init__(self, repo: 'Repo', binsha: bytes, tree: Union[Tree, None] = None,
128128
as what time.altzone returns. The sign is inverted compared to git's
129129
UTC timezone."""
130130
super(Commit,self).__init__(repo,binsha)
131+
self.binsha=binsha
131132
iftreeisnotNone:
132133
assertisinstance(tree,Tree),"Tree needs to be a Tree instance, was %s"%type(tree)
133134
iftreeisnotNone:

‎git/objects/util.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ def list_traverse(self: T_TIobj, *args: Any, **kwargs: Any) -> IterableList[T_TI
493493
returnsuper(TraversableIterableObj,self)._list_traverse(*args,**kwargs)
494494

495495
@overload# type: ignore
496+
deftraverse(self:T_TIobj
497+
)->Iterator[T_TIobj]:
498+
...
499+
500+
@overload
496501
deftraverse(self:T_TIobj,
497502
predicate:Callable[[Union[T_TIobj,Tuple[Union[T_TIobj,None],T_TIobj]],int],bool],
498503
prune:Callable[[Union[T_TIobj,Tuple[Union[T_TIobj,None],T_TIobj]],int],bool],

‎git/refs/head.py‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fromgit.configimportSectionConstraint
1+
fromgit.configimportGitConfigParser,SectionConstraint
22
fromgit.utilimportjoin_path
33
fromgit.excimportGitCommandError
44

@@ -203,7 +203,7 @@ def rename(self, new_path: PathLike, force: bool = False) -> 'Head':
203203
self.path="%s/%s"% (self._common_path_default,new_path)
204204
returnself
205205

206-
defcheckout(self,force:bool=False,**kwargs:Any):
206+
defcheckout(self,force:bool=False,**kwargs:Any)->Union['HEAD','Head']:
207207
"""Checkout this head by setting the HEAD to this reference, by updating the index
208208
to reflect the tree we point to and by updating the working tree to reflect
209209
the latest index.
@@ -235,10 +235,11 @@ def checkout(self, force: bool = False, **kwargs: Any):
235235
self.repo.git.checkout(self,**kwargs)
236236
ifself.repo.head.is_detached:
237237
returnself.repo.head
238-
returnself.repo.active_branch
238+
else:
239+
returnself.repo.active_branch
239240

240241
#{ Configuration
241-
def_config_parser(self,read_only:bool)->SectionConstraint:
242+
def_config_parser(self,read_only:bool)->SectionConstraint[GitConfigParser]:
242243
ifread_only:
243244
parser=self.repo.config_reader()
244245
else:
@@ -247,13 +248,13 @@ def _config_parser(self, read_only: bool) -> SectionConstraint:
247248

248249
returnSectionConstraint(parser,'branch "%s"'%self.name)
249250

250-
defconfig_reader(self)->SectionConstraint:
251+
defconfig_reader(self)->SectionConstraint[GitConfigParser]:
251252
"""
252253
:return: A configuration parser instance constrained to only read
253254
this instance's values"""
254255
returnself._config_parser(read_only=True)
255256

256-
defconfig_writer(self)->SectionConstraint:
257+
defconfig_writer(self)->SectionConstraint[GitConfigParser]:
257258
"""
258259
:return: A configuration writer instance with read-and write access
259260
to options of this head"""

‎git/refs/reference.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def __str__(self) -> str:
6262

6363
#{ Interface
6464

65-
defset_object(self,object:Commit_ish,logmsg:Union[str,None]=None)->'Reference':# @ReservedAssignment
65+
# @ReservedAssignment
66+
defset_object(self,object:Union[Commit_ish,'SymbolicReference'],logmsg:Union[str,None]=None
67+
)->'SymbolicReference':
6668
"""Special version which checks if the head-log needs an update as well
6769
:return: self"""
6870
oldbinsha=None

‎git/refs/symbolic.py‎

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
BadName
1717
)
1818

19-
from .logimportRefLog
19+
from .logimportRefLog,RefLogEntry
2020

2121
# typing ------------------------------------------------------------------
2222

@@ -26,6 +26,8 @@
2626
ifTYPE_CHECKING:
2727
fromgit.repoimportRepo
2828
fromgit.refsimportReference,Head,TagReference,RemoteReference
29+
fromgit.configimportGitConfigParser
30+
fromgit.objects.commitimportActor
2931

3032
T_References=TypeVar('T_References',bound='SymbolicReference')
3133

@@ -229,11 +231,13 @@ def set_commit(self, commit: Union[Commit, 'SymbolicReference', str],
229231
invalid_type=False
230232
ifisinstance(commit,Object):
231233
invalid_type=commit.type!=Commit.type
234+
commit=cast('Commit',commit)
232235
elifisinstance(commit,SymbolicReference):
233236
invalid_type=commit.object.type!=Commit.type
234237
else:
235238
try:
236-
invalid_type=self.repo.rev_parse(commit).type!=Commit.type
239+
commit=self.repo.rev_parse(commit)
240+
invalid_type=commit.type!=Commit.type
237241
except (BadObject,BadName)ase:
238242
raiseValueError("Invalid object: %s"%commit)frome
239243
# END handle exception
@@ -249,7 +253,9 @@ def set_commit(self, commit: Union[Commit, 'SymbolicReference', str],
249253
# return self
250254
returnNone
251255

252-
defset_object(self,object,logmsg=None):# @ReservedAssignment
256+
defset_object(self,object:Union[Commit_ish,'SymbolicReference'],
257+
logmsg:Union[str,None]=None
258+
)->'SymbolicReference':# @ReservedAssignment
253259
"""Set the object we point to, possibly dereference our symbolic reference first.
254260
If the reference does not exist, it will be created
255261
@@ -276,8 +282,8 @@ def set_object(self, object, logmsg=None): # @ReservedAssignment
276282
# set the commit on our reference
277283
returnself._get_reference().set_object(object,logmsg)
278284

279-
commit=property(_get_commit,set_commit,doc="Query or set commits directly")
280-
object=property(_get_object,set_object,doc="Return the object our ref currently refers to")
285+
commit=cast('Commit',property(_get_commit,set_commit,doc="Query or set commits directly"))
286+
object=property(_get_object,set_object,doc="Return the object our ref currently refers to")# type: ignore
281287

282288
def_get_reference(self
283289
)->Union['Head','RemoteReference','TagReference','Reference']:
@@ -290,7 +296,7 @@ def _get_reference(self
290296
returnself.from_path(self.repo,target_ref_path)
291297

292298
defset_reference(self,ref:Union[str,Commit_ish,'SymbolicReference'],logmsg:Union[str,None]=None
293-
)->None:
299+
)->'SymbolicReference':
294300
"""Set ourselves to the given ref. It will stay a symbol if the ref is a Reference.
295301
Otherwise an Object, given as Object instance or refspec, is assumed and if valid,
296302
will be set which effectively detaches the refererence if it was a purely
@@ -331,7 +337,7 @@ def set_reference(self, ref: Union[str, Commit_ish, 'SymbolicReference'], logmsg
331337
raiseTypeError("Require commit, got %r"%obj)
332338
# END verify type
333339

334-
oldbinsha=None
340+
oldbinsha:bytes=b''
335341
iflogmsgisnotNone:
336342
try:
337343
oldbinsha=self.commit.binsha
@@ -357,15 +363,15 @@ def set_reference(self, ref: Union[str, Commit_ish, 'SymbolicReference'], logmsg
357363
iflogmsgisnotNone:
358364
self.log_append(oldbinsha,logmsg)
359365

360-
returnNone
366+
returnself
361367

362368
@property
363369
defreference(self)->Union['Head','RemoteReference','TagReference','Reference']:
364370
returnself._get_reference()
365371

366372
@reference.setter
367373
defreference(self,ref:Union[str,Commit_ish,'SymbolicReference'],logmsg:Union[str,None]=None
368-
)->None:
374+
)->'SymbolicReference':
369375
returnself.set_reference(ref=ref,logmsg=logmsg)
370376

371377
defis_valid(self)->bool:
@@ -392,7 +398,7 @@ def is_detached(self):
392398
exceptTypeError:
393399
returnTrue
394400

395-
deflog(self):
401+
deflog(self)->'RefLog':
396402
"""
397403
:return: RefLog for this reference. Its last entry reflects the latest change
398404
applied to this reference
@@ -401,7 +407,8 @@ def log(self):
401407
instead of calling this method repeatedly. It should be considered read-only."""
402408
returnRefLog.from_file(RefLog.path(self))
403409

404-
deflog_append(self,oldbinsha,message,newbinsha=None):
410+
deflog_append(self,oldbinsha:bytes,message:Union[str,None],
411+
newbinsha:Union[bytes,None]=None)->'RefLogEntry':
405412
"""Append a logentry to the logfile of this ref
406413
407414
:param oldbinsha: binary sha this ref used to point to
@@ -413,15 +420,19 @@ def log_append(self, oldbinsha, message, newbinsha=None):
413420
# correct to allow overriding the committer on a per-commit level.
414421
# See https://github.com/gitpython-developers/GitPython/pull/146
415422
try:
416-
committer_or_reader=self.commit.committer
423+
committer_or_reader:Union['Actor','GitConfigParser']=self.commit.committer
417424
exceptValueError:
418425
committer_or_reader=self.repo.config_reader()
419426
# end handle newly cloned repositories
420-
returnRefLog.append_entry(committer_or_reader,RefLog.path(self),oldbinsha,
421-
(newbinshaisNoneandself.commit.binsha)ornewbinsha,
422-
message)
427+
ifnewbinshaisNone:
428+
newbinsha=self.commit.binsha
429+
430+
ifmessageisNone:
431+
message=''
432+
433+
returnRefLog.append_entry(committer_or_reader,RefLog.path(self),oldbinsha,newbinsha,message)
423434

424-
deflog_entry(self,index):
435+
deflog_entry(self,index:int)->RefLogEntry:
425436
""":return: RefLogEntry at the given index
426437
:param index: python list compatible positive or negative index
427438
@@ -540,7 +551,7 @@ def _create(cls: Type[T_References], repo: 'Repo', path: PathLike, resolve: bool
540551

541552
@classmethod
542553
defcreate(cls:Type[T_References],repo:'Repo',path:PathLike,
543-
reference:Union[Commit_ish,str,'SymbolicReference']='SymbolicReference',
554+
reference:Union[str,'SymbolicReference']='SymbolicReference',
544555
logmsg:Union[str,None]=None,force:bool=False,**kwargs:Any)->T_References:
545556
"""Create a new symbolic reference, hence a reference pointing , to another reference.
546557
@@ -553,7 +564,7 @@ def create(cls: Type[T_References], repo: 'Repo', path: PathLike,
553564
554565
:param reference:
555566
The reference to which the new symbolic reference should point to.
556-
If it is a commit'ish, the symbolic ref will be detached.
567+
If it is aref to acommit'ish, the symbolic ref will be detached.
557568
558569
:param force:
559570
if True, force creation even if a symbolic reference with that name already exists.

‎git/refs/tag.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def object(self) -> Commit_ish: # type: ignore[override]
7070

7171
@classmethod
7272
defcreate(cls:Type['TagReference'],repo:'Repo',path:PathLike,
73-
reference:Union[Commit_ish,str,'SymbolicReference']='HEAD',
73+
reference:Union[str,'SymbolicReference']='HEAD',
7474
logmsg:Union[str,None]=None,
7575
force:bool=False,**kwargs:Any)->'TagReference':
7676
"""Create a new tag reference.
@@ -80,7 +80,7 @@ def create(cls: Type['TagReference'], repo: 'Repo', path: PathLike,
8080
The prefix refs/tags is implied
8181
8282
:param ref:
83-
A reference to theobject you want to tag.It can be a commit, tree or
83+
A reference to theObject you want to tag.The Object can be a commit, tree or
8484
blob.
8585
8686
:param logmsg:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp