2424from funcy import cached_property , reraise
2525
2626from scmrepo .exceptions import AuthError , CloneError , InvalidRemote , RevError , SCMError
27+ from scmrepo .git .backend .base import BaseGitBackend , SyncStatus
28+ from scmrepo .git .config import Config
29+ from scmrepo .git .objects import GitObject , GitTag
2730from scmrepo .progress import GitProgressReporter
2831from scmrepo .utils import relpath
2932
30- from ...config import Config
31- from ...objects import GitObject , GitTag
32- from ..base import BaseGitBackend , SyncStatus
33-
3433if TYPE_CHECKING :
3534 from dulwich .client import SSHVendor
3635 from dulwich .config import ConfigFile , StackedConfig
3736 from dulwich .repo import Repo
3837
38+ from scmrepo .git .objects import GitCommit
3939 from scmrepo .progress import GitProgressEvent
4040
41- from ...objects import GitCommit
42-
4341
4442logger = logging .getLogger (__name__ )
4543
@@ -82,7 +80,7 @@ def mode(self) -> int:
8280
8381 def scandir (self ) -> Iterable ["DulwichObject" ]:
8482 tree = self .repo [self ._sha ]
85- for entry in tree .iteritems (): # noqa: B301
83+ for entry in tree .iteritems ():
8684 yield DulwichObject (self .repo , entry .path .decode (), entry .mode , entry .sha )
8785
8886 @cached_property
@@ -232,7 +230,7 @@ def clone(
232230 url : str ,
233231 to_path : str ,
234232 shallow_branch : Optional [str ] = None ,
235- progress : Callable [["GitProgressEvent" ], None ] = None ,
233+ progress : Optional [ Callable [["GitProgressEvent" ], None ] ] = None ,
236234 bare : bool = False ,
237235 mirror : bool = False ,
238236 ):
@@ -271,7 +269,7 @@ def clone(
271269 cls ._set_mirror (repo , progress = progress )
272270 else :
273271 cls ._set_default_tracking_branch (repo )
274- except Exception as exc :
272+ except Exception as exc : # noqa: BLE001
275273 raise CloneError (url , to_path ) from exc
276274
277275 @staticmethod
@@ -291,7 +289,7 @@ def _set_default_tracking_branch(repo: "Repo"):
291289
292290 @staticmethod
293291 def _set_mirror (
294- repo : "Repo" , progress : Callable [["GitProgressEvent" ], None ] = None
292+ repo : "Repo" , progress : Optional [ Callable [["GitProgressEvent" ], None ] ] = None
295293 ):
296294 from dulwich .porcelain import NoneStream , fetch
297295
@@ -458,10 +456,7 @@ def untracked_files(self) -> Iterable[str]:
458456 def is_tracked (self , path : str ) -> bool :
459457 rel = relpath (path , self .root_dir ).replace (os .path .sep , "/" ).encode ()
460458 rel_dir = rel + b"/"
461- for p in self .repo .open_index ():
462- if p == rel or p .startswith (rel_dir ):
463- return True
464- return False
459+ return any (p == rel or p .startswith (rel_dir ) for p in self .repo .open_index ())
465460
466461 def is_dirty (self , untracked_files : bool = False ) -> bool :
467462 kwargs : Dict [str , Any ] = {} if untracked_files else {"untracked_files" : "no" }
@@ -590,7 +585,7 @@ def iter_remote_refs(self, url: str, base: Optional[str] = None, **kwargs):
590585 try :
591586 _remote , location = get_remote_repo (self .repo , url )
592587 client , path = get_transport_and_path (location , ** kwargs )
593- except Exception as exc :
588+ except Exception as exc : # noqa: BLE001
594589 raise InvalidRemote (url ) from exc
595590
596591 try :
@@ -616,7 +611,7 @@ def push_refspecs( # noqa: C901
616611 refspecs : Union [str , Iterable [str ]],
617612 force : bool = False ,
618613 on_diverged : Optional [Callable [[str , str ], bool ]] = None ,
619- progress : Callable [["GitProgressEvent" ], None ] = None ,
614+ progress : Optional [ Callable [["GitProgressEvent" ], None ] ] = None ,
620615 ** kwargs ,
621616 ) -> Mapping [str , SyncStatus ]:
622617 from dulwich .client import HTTPUnauthorized , get_transport_and_path
@@ -627,7 +622,7 @@ def push_refspecs( # noqa: C901
627622 try :
628623 _remote , location = get_remote_repo (self .repo , url )
629624 client , path = get_transport_and_path (location , ** kwargs )
630- except Exception as exc :
625+ except Exception as exc : # noqa: BLE001
631626 raise SCMError (f"'{ url } ' is not a valid Git remote or URL" ) from exc
632627
633628 change_result = {}
@@ -700,7 +695,7 @@ def fetch_refspecs(
700695 refspecs : Union [str , Iterable [str ]],
701696 force : bool = False ,
702697 on_diverged : Optional [Callable [[str , str ], bool ]] = None ,
703- progress : Callable [["GitProgressEvent" ], None ] = None ,
698+ progress : Optional [ Callable [["GitProgressEvent" ], None ] ] = None ,
704699 ** kwargs ,
705700 ) -> Mapping [str , SyncStatus ]:
706701 from dulwich .client import get_transport_and_path
@@ -868,7 +863,7 @@ def diff(self, rev_a: str, rev_b: str, binary=False) -> str:
868863 write_tree_diff (buf , self .repo .object_store , commit_a .tree , commit_b .tree )
869864 return buf .getvalue ().decode ("utf-8" )
870865
871- def reset (self , hard : bool = False , paths : Iterable [str ] = None ):
866+ def reset (self , hard : bool = False , paths : Optional [ Iterable [str ] ] = None ):
872867 raise NotImplementedError
873868
874869 def checkout_index (
@@ -920,7 +915,7 @@ def validate_git_remote(self, url: str, **kwargs):
920915 try :
921916 _ , location = get_remote_repo (self .repo , url )
922917 client , path = get_transport_and_path (location , ** kwargs )
923- except Exception as exc :
918+ except Exception as exc : # noqa: BLE001
924919 raise InvalidRemote (url ) from exc
925920 if isinstance (client , LocalGitClient ) and not os .path .exists (
926921 os .path .join ("" , path )
0 commit comments