77from unittest import SkipTest
88import uuid
99
10+ from git import IndexFile
11+
1012import git
1113from git .cmd import Git
1214from git .compat import (
4951
5052
5153# typing ----------------------------------------------------------------------
52- from typing import Dict , TYPE_CHECKING
54+ from typing import Callable , Dict , TYPE_CHECKING
5355from typing import Any , Iterator , Union
5456
5557from git .types import Commit_ish , PathLike
@@ -131,14 +133,14 @@ def __init__(self, repo: 'Repo', binsha: bytes,
131133 if url is not None :
132134 self ._url = url
133135 if branch_path is not None :
134- assert isinstance (branch_path , str )
136+ # assert isinstance(branch_path, str)
135137 self ._branch_path = branch_path
136138 if name is not None :
137139 self ._name = name
138140
139141 def _set_cache_ (self , attr : str ) -> None :
140142 if attr in ('path' , '_url' , '_branch_path' ):
141- reader = self .config_reader ()
143+ reader : SectionConstraint = self .config_reader ()
142144 # default submodule values
143145 try :
144146 self .path = reader .get ('path' )
@@ -807,7 +809,8 @@ def move(self, module_path, configuration=True, module=True):
807809 return self
808810
809811 @unbare_repo
810- def remove (self , module = True , force = False , configuration = True , dry_run = False ):
812+ def remove (self , module : bool = True , force : bool = False ,
813+ configuration : bool = True , dry_run : bool = False ) -> 'Submodule' :
811814 """Remove this submodule from the repository. This will remove our entry
812815 from the .gitmodules file and the entry in the .git / config file.
813816
@@ -861,7 +864,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
861864 # TODO: If we run into permission problems, we have a highly inconsistent
862865 # state. Delete the .git folders last, start with the submodules first
863866 mp = self .abspath
864- method = None
867+ method : Union [ None , Callable [[ PathLike ], None ]] = None
865868 if osp .islink (mp ):
866869 method = os .remove
867870 elif osp .isdir (mp ):
@@ -928,7 +931,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
928931 rmtree (git_dir )
929932 except Exception as ex :
930933 if HIDE_WINDOWS_KNOWN_ERRORS :
931- raise SkipTest ("FIXME: fails with: PermissionError\n %s" , ex ) from ex
934+ raise SkipTest (f "FIXME: fails with: PermissionError\n { ex } " ) from ex
932935 else :
933936 raise
934937 # end handle separate bare repository
@@ -961,7 +964,7 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
961964
962965 return self
963966
964- def set_parent_commit (self , commit : Union [Commit_ish , None ], check = True ):
967+ def set_parent_commit (self , commit : Union [Commit_ish , None ], check : bool = True ) -> 'Submodule' :
965968 """Set this instance to use the given commit whose tree is supposed to
966969 contain the .gitmodules blob.
967970
@@ -1009,7 +1012,7 @@ def set_parent_commit(self, commit: Union[Commit_ish, None], check=True):
10091012 return self
10101013
10111014 @unbare_repo
1012- def config_writer (self , index = None , write = True ):
1015+ def config_writer (self , index : Union [ IndexFile , None ] = None , write : bool = True ) -> SectionConstraint :
10131016 """:return: a config writer instance allowing you to read and write the data
10141017 belonging to this submodule into the .gitmodules file.
10151018
@@ -1030,7 +1033,7 @@ def config_writer(self, index=None, write=True):
10301033 return writer
10311034
10321035 @unbare_repo
1033- def rename (self , new_name ) :
1036+ def rename (self , new_name : str ) -> 'Submodule' :
10341037 """Rename this submodule
10351038 :note: This method takes care of renaming the submodule in various places, such as
10361039
@@ -1081,7 +1084,7 @@ def rename(self, new_name):
10811084 #{ Query Interface
10821085
10831086 @unbare_repo
1084- def module (self ):
1087+ def module (self ) -> 'Repo' :
10851088 """:return: Repo instance initialized from the repository at our submodule path
10861089 :raise InvalidGitRepositoryError: if a repository was not available. This could
10871090 also mean that it was not yet initialized"""
@@ -1098,7 +1101,7 @@ def module(self):
10981101 raise InvalidGitRepositoryError ("Repository at %r was not yet checked out" % module_checkout_abspath )
10991102 # END handle exceptions
11001103
1101- def module_exists (self ):
1104+ def module_exists (self ) -> bool :
11021105 """:return: True if our module exists and is a valid git repository. See module() method"""
11031106 try :
11041107 self .module ()
@@ -1107,7 +1110,7 @@ def module_exists(self):
11071110 return False
11081111 # END handle exception
11091112
1110- def exists (self ):
1113+ def exists (self ) -> bool :
11111114 """
11121115 :return: True if the submodule exists, False otherwise. Please note that
11131116 a submodule may exist ( in the .gitmodules file) even though its module
0 commit comments