1616 Iterable ,
1717 IterableList ,
1818 RemoteProgress ,
19- CallableRemoteProgress
19+ CallableRemoteProgress ,
2020)
2121from git .util import (
2222 join_path ,
3636
3737# typing-------------------------------------------------------
3838
39- from typing import Any , Callable , Dict , Optional , TYPE_CHECKING , Union , cast , overload
39+ from typing import Any , Callable , Dict , Generator , Optional , TYPE_CHECKING , Union , cast , overload
4040
4141from git .types import PathLike , Literal
4242
@@ -276,7 +276,8 @@ def refresh(cls) -> Literal[True]:
276276
277277 return True
278278
279- def __init__ (self , ref : SymbolicReference , flags : int , note : str = '' , old_commit : Optional ['Commit' ] = None ,
279+ def __init__ (self , ref : SymbolicReference , flags : int , note : str = '' ,
280+ old_commit : Union [Commit , TagReference , Tree , Blob , None ] = None ,
280281 remote_ref_path : Optional [PathLike ] = None ) -> None :
281282 """
282283 Initialize a new instance
@@ -341,7 +342,7 @@ def _from_line(cls, repo: 'Repo', line: str, fetch_line: str) -> 'FetchInfo':
341342 # END control char exception handling
342343
343344 # parse operation string for more info - makes no sense for symbolic refs, but we parse it anyway
344- old_commit = None
345+ old_commit = None # type: Union[Commit, TagReference, Tree, Blob, None]
345346 is_tag_operation = False
346347 if 'rejected' in operation :
347348 flags |= cls .REJECTED
@@ -455,24 +456,24 @@ def __getattr__(self, attr: str) -> Any:
455456 return super (Remote , self ).__getattr__ (attr )
456457 # END handle exception
457458
458- def _config_section_name (self ):
459+ def _config_section_name (self ) -> str :
459460 return 'remote "%s"' % self .name
460461
461- def _set_cache_ (self , attr ) :
462+ def _set_cache_ (self , attr : str ) -> Any :
462463 if attr == "_config_reader" :
463464 # NOTE: This is cached as __getattr__ is overridden to return remote config values implicitly, such as
464465 # in print(r.pushurl)
465466 self ._config_reader = SectionConstraint (self .repo .config_reader ("repository" ), self ._config_section_name ())
466467 else :
467468 super (Remote , self )._set_cache_ (attr )
468469
469- def __str__ (self ):
470+ def __str__ (self ) -> str :
470471 return self .name
471472
472- def __repr__ (self ):
473+ def __repr__ (self ) -> str :
473474 return '<git.%s "%s">' % (self .__class__ .__name__ , self .name )
474475
475- def __eq__ (self , other ) :
476+ def __eq__ (self , other : object ) -> bool :
476477 return isinstance (other , type (self )) and self .name == other .name
477478
478479 def __ne__ (self , other ):
@@ -496,7 +497,7 @@ def exists(self) -> bool:
496497 # end
497498
498499 @classmethod
499- def iter_items (cls , repo ) :
500+ def iter_items (cls , repo : 'Repo' ) -> Generator [ 'Remote' , None , None ] :
500501 """:return: Iterator yielding Remote objects of the given repository"""
501502 for section in repo .config_reader ("repository" ).sections ():
502503 if not section .startswith ('remote ' ):
@@ -508,7 +509,7 @@ def iter_items(cls, repo):
508509 yield Remote (repo , section [lbound + 1 :rbound ])
509510 # END for each configuration section
510511
511- def set_url (self , new_url , old_url = None , ** kwargs ) :
512+ def set_url (self , new_url : str , old_url : Optional [ str ] = None , ** kwargs : Any ) -> 'Remote' :
512513 """Configure URLs on current remote (cf command git remote set_url)
513514
514515 This command manages URLs on the remote.
@@ -525,7 +526,7 @@ def set_url(self, new_url, old_url=None, **kwargs):
525526 self .repo .git .remote (scmd , self .name , new_url , ** kwargs )
526527 return self
527528
528- def add_url (self , url , ** kwargs ) :
529+ def add_url (self , url : str , ** kwargs : Any ) -> 'Remote' :
529530 """Adds a new url on current remote (special case of git remote set_url)
530531
531532 This command adds new URLs to a given remote, making it possible to have
@@ -536,7 +537,7 @@ def add_url(self, url, **kwargs):
536537 """
537538 return self .set_url (url , add = True )
538539
539- def delete_url (self , url , ** kwargs ) :
540+ def delete_url (self , url : str , ** kwargs : Any ) -> 'Remote' :
540541 """Deletes a new url on current remote (special case of git remote set_url)
541542
542543 This command deletes new URLs to a given remote, making it possible to have
@@ -551,7 +552,8 @@ def delete_url(self, url, **kwargs):
551552 def urls (self ):
552553 """:return: Iterator yielding all configured URL targets on a remote as strings"""
553554 try :
554- remote_details = self .repo .git .remote ("get-url" , "--all" , self .name )
555+ # can replace cast with type assert?
556+ remote_details = cast (str , self .repo .git .remote ("get-url" , "--all" , self .name ))
555557 for line in remote_details .split ('\n ' ):
556558 yield line
557559 except GitCommandError as ex :
@@ -562,14 +564,14 @@ def urls(self):
562564 #
563565 if 'Unknown subcommand: get-url' in str (ex ):
564566 try :
565- remote_details = self .repo .git .remote ("show" , self .name )
567+ remote_details = cast ( str , self .repo .git .remote ("show" , self .name ) )
566568 for line in remote_details .split ('\n ' ):
567569 if ' Push URL:' in line :
568570 yield line .split (': ' )[- 1 ]
569571 except GitCommandError as ex :
570572 if any (msg in str (ex ) for msg in ['correct access rights' , 'cannot run ssh' ]):
571573 # If ssh is not setup to access this repository, see issue 694
572- remote_details = self .repo .git .config ('--get-all' , 'remote.%s.url' % self .name )
574+ remote_details = cast ( str , self .repo .git .config ('--get-all' , 'remote.%s.url' % self .name ) )
573575 for line in remote_details .split ('\n ' ):
574576 yield line
575577 else :
0 commit comments