36
36
from git .remote import Remote
37
37
from git .repo .base import Repo
38
38
from git .config import GitConfigParser , SectionConstraint
39
- from git .objects .base import IndexObject
39
+ # from git.objects.base import IndexObject
40
40
41
41
42
42
from .types import (Literal , SupportsIndex , # because behind py version guards
43
- PathLike , HSH_TD , Total_TD , Files_TD ) # aliases
43
+ PathLike , HSH_TD , Total_TD , Files_TD , # aliases
44
+ Has_id_attribute )
44
45
45
- T_IterableObj = TypeVar ('T_IterableObj' , bound = Union ['IterableObj' , 'IndexObject ' ], covariant = True )
46
+ T_IterableObj = TypeVar ('T_IterableObj' , bound = Union ['IterableObj' , 'Has_id_attribute ' ], covariant = True )
46
47
# So IterableList[Head] is subtype of IterableList[IterableObj]
47
48
48
49
# ---------------------------------------------------------------------
82
83
HIDE_WINDOWS_KNOWN_ERRORS = is_win and os .environ .get ('HIDE_WINDOWS_KNOWN_ERRORS' , True )
83
84
HIDE_WINDOWS_FREEZE_ERRORS = is_win and os .environ .get ('HIDE_WINDOWS_FREEZE_ERRORS' , True )
84
85
85
- #{ Utility Methods
86
+ # { Utility Methods
86
87
87
88
T = TypeVar ('T' )
88
89
@@ -247,7 +248,7 @@ def is_exec(fpath: str) -> bool:
247
248
248
249
def _cygexpath (drive : Optional [str ], path : str ) -> str :
249
250
if osp .isabs (path ) and not drive :
250
- ## Invoked from `cygpath()` directly with `D:Apps\123`?
251
+ # Invoked from `cygpath()` directly with `D:Apps\123`?
251
252
# It's an error, leave it alone just slashes)
252
253
p = path # convert to str if AnyPath given
253
254
else :
@@ -265,8 +266,8 @@ def _cygexpath(drive: Optional[str], path: str) -> str:
265
266
266
267
267
268
_cygpath_parsers = (
268
- ## See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
269
- ## and: https://www.cygwin.com/cygwin-ug-net/using.html#unc-paths
269
+ # See: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
270
+ # and: https://www.cygwin.com/cygwin-ug-net/using.html#unc-paths
270
271
(re .compile (r"\\\\\?\\UNC\\([^\\]+)\\([^\\]+)(?:\\(.*))?" ),
271
272
(lambda server , share , rest_path : '//%s/%s/%s' % (server , share , rest_path .replace ('\\ ' , '/' ))),
272
273
False
@@ -297,7 +298,7 @@ def _cygexpath(drive: Optional[str], path: str) -> str:
297
298
def cygpath (path : str ) -> str :
298
299
"""Use :meth:`git.cmd.Git.polish_url()` instead, that works on any environment."""
299
300
path = str (path ) # ensure is str and not AnyPath.
300
- #Fix to use Paths when 3.5 dropped. or to be just str if only for urls?
301
+ # Fix to use Paths when 3.5 dropped. or to be just str if only for urls?
301
302
if not path .startswith (('/cygdrive' , '//' )):
302
303
for regex , parser , recurse in _cygpath_parsers :
303
304
match = regex .match (path )
@@ -357,7 +358,7 @@ def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
357
358
res = py_where (git_executable )
358
359
git_dir = osp .dirname (res [0 ]) if res else ""
359
360
360
- ## Just a name given, not a real path.
361
+ # Just a name given, not a real path.
361
362
uname_cmd = osp .join (git_dir , 'uname' )
362
363
process = subprocess .Popen ([uname_cmd ], stdout = subprocess .PIPE ,
363
364
universal_newlines = True )
@@ -378,7 +379,7 @@ def get_user_id() -> str:
378
379
379
380
def finalize_process (proc : subprocess .Popen , ** kwargs : Any ) -> None :
380
381
"""Wait for the process (clone, fetch, pull or push) and handle its errors accordingly"""
381
- ## TODO: No close proc-streams??
382
+ # TODO: No close proc-streams??
382
383
proc .wait (** kwargs )
383
384
384
385
@@ -432,9 +433,9 @@ def remove_password_if_present(cmdline):
432
433
return new_cmdline
433
434
434
435
435
- #} END utilities
436
+ # } END utilities
436
437
437
- #{ Classes
438
+ # { Classes
438
439
439
440
440
441
class RemoteProgress (object ):
@@ -984,15 +985,15 @@ def __contains__(self, attr: object) -> bool:
984
985
return False
985
986
# END handle membership
986
987
987
- def __getattr__ (self , attr : str ) -> Any :
988
+ def __getattr__ (self , attr : str ) -> T_IterableObj :
988
989
attr = self ._prefix + attr
989
990
for item in self :
990
991
if getattr (item , self ._id_attr ) == attr :
991
992
return item
992
993
# END for each item
993
994
return list .__getattribute__ (self , attr )
994
995
995
- def __getitem__ (self , index : Union [SupportsIndex , int , slice , str ]) -> Any :
996
+ def __getitem__ (self , index : Union [SupportsIndex , int , slice , str ]) -> 'T_IterableObj' : # type: ignore
996
997
997
998
assert isinstance (index , (int , str , slice )), "Index of IterableList should be an int or str"
998
999
@@ -1007,7 +1008,7 @@ def __getitem__(self, index: Union[SupportsIndex, int, slice, str]) -> Any:
1007
1008
raise IndexError ("No item found with id %r" % (self ._prefix + index )) from e
1008
1009
# END handle getattr
1009
1010
1010
- def __delitem__ (self , index : Union [SupportsIndex , int , slice , str ]) -> Any :
1011
+ def __delitem__ (self , index : Union [SupportsIndex , int , slice , str ]) -> None :
1011
1012
1012
1013
assert isinstance (index , (int , str )), "Index of IterableList should be an int or str"
1013
1014
@@ -1101,7 +1102,7 @@ def iter_items(cls, repo: 'Repo', *args: Any, **kwargs: Any
1101
1102
:return: iterator yielding Items"""
1102
1103
raise NotImplementedError ("To be implemented by Subclass" )
1103
1104
1104
- #} END classes
1105
+ # } END classes
1105
1106
1106
1107
1107
1108
class NullHandler (logging .Handler ):
0 commit comments