15
15
PIPE
16
16
)
17
17
import subprocess
18
- import sys
19
18
import threading
20
19
from textwrap import dedent
21
20
@@ -539,7 +538,7 @@ def __iter__(self) -> 'Git.CatFileContentStream':
539
538
return self
540
539
541
540
def __next__ (self ) -> bytes :
542
- return self . next ()
541
+ return next (self )
543
542
544
543
def next (self ) -> bytes :
545
544
line = self .readline ()
@@ -566,11 +565,11 @@ def __init__(self, working_dir: Union[None, PathLike] = None):
566
565
.git directory in case of bare repositories."""
567
566
super (Git , self ).__init__ ()
568
567
self ._working_dir = expand_path (working_dir )
569
- self ._git_options = () # type : Union[List[str], Tuple[str, ...]]
570
- self ._persistent_git_options = [] # type: List[str ]
568
+ self ._git_options : Union [List [str ], Tuple [str , ...]] = ()
569
+ self ._persistent_git_options : List [ str ] = [ ]
571
570
572
571
# Extra environment variables to pass to git commands
573
- self ._environment = {} # type : Dict[str, str]
572
+ self ._environment : Dict [str , str ] = {}
574
573
575
574
# cached command slots
576
575
self .cat_file_header = None
@@ -604,35 +603,35 @@ def _set_cache_(self, attr: str) -> None:
604
603
process_version = self ._call_process ('version' ) # should be as default *args and **kwargs used
605
604
version_numbers = process_version .split (' ' )[2 ]
606
605
607
- self ._version_info = tuple (
608
- int (n ) for n in version_numbers .split ('.' )[:4 ] if n .isdigit ()
609
- ) # type: Tuple[int, int, int, int] # type: ignore
606
+ self ._version_info = cast ( Tuple [ int , int , int , int ],
607
+ tuple ( int (n ) for n in version_numbers .split ('.' )[:4 ] if n .isdigit () )
608
+ )
610
609
else :
611
610
super (Git , self )._set_cache_ (attr )
612
611
# END handle version info
613
612
614
- @property
613
+ @ property
615
614
def working_dir (self ) -> Union [None , PathLike ]:
616
615
""":return: Git directory we are working on"""
617
616
return self ._working_dir
618
617
619
- @property
618
+ @ property
620
619
def version_info (self ) -> Tuple [int , int , int , int ]:
621
620
"""
622
621
:return: tuple(int, int, int, int) tuple with integers representing the major, minor
623
622
and additional version numbers as parsed from git version.
624
623
This value is generated on demand and is cached"""
625
624
return self ._version_info
626
625
627
- @overload
626
+ @ overload
628
627
def execute (self ,
629
628
command : Union [str , Sequence [Any ]],
630
629
* ,
631
630
as_process : Literal [True ]
632
631
) -> 'AutoInterrupt' :
633
632
...
634
633
635
- @overload
634
+ @ overload
636
635
def execute (self ,
637
636
command : Union [str , Sequence [Any ]],
638
637
* ,
@@ -641,7 +640,7 @@ def execute(self,
641
640
) -> Union [str , Tuple [int , str , str ]]:
642
641
...
643
642
644
- @overload
643
+ @ overload
645
644
def execute (self ,
646
645
command : Union [str , Sequence [Any ]],
647
646
* ,
@@ -650,7 +649,7 @@ def execute(self,
650
649
) -> Union [bytes , Tuple [int , bytes , str ]]:
651
650
...
652
651
653
- @overload
652
+ @ overload
654
653
def execute (self ,
655
654
command : Union [str , Sequence [Any ]],
656
655
* ,
@@ -660,7 +659,7 @@ def execute(self,
660
659
) -> str :
661
660
...
662
661
663
- @overload
662
+ @ overload
664
663
def execute (self ,
665
664
command : Union [str , Sequence [Any ]],
666
665
* ,
@@ -799,10 +798,7 @@ def execute(self,
799
798
if kill_after_timeout :
800
799
raise GitCommandError (redacted_command , '"kill_after_timeout" feature is not supported on Windows.' )
801
800
else :
802
- if sys .version_info [0 ] > 2 :
803
- cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
804
- else :
805
- cmd_not_found_exception = OSError
801
+ cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
806
802
# end handle
807
803
808
804
stdout_sink = (PIPE
@@ -872,8 +868,8 @@ def _kill_process(pid: int) -> None:
872
868
873
869
# Wait for the process to return
874
870
status = 0
875
- stdout_value = b'' # type : Union[str, bytes]
876
- stderr_value = b'' # type : Union[str, bytes]
871
+ stdout_value : Union [str , bytes ] = b''
872
+ stderr_value : Union [str , bytes ] = b''
877
873
newline = "\n " if universal_newlines else b"\n "
878
874
try :
879
875
if output_stream is None :
@@ -1070,8 +1066,8 @@ def _call_process(self, method: str, *args: Any, **kwargs: Any
1070
1066
It contains key-values for the following:
1071
1067
- the :meth:`execute()` kwds, as listed in :var:`execute_kwargs`;
1072
1068
- "command options" to be converted by :meth:`transform_kwargs()`;
1073
- - the `'insert_kwargs_after'` key which its value must match one of ``*args``,
1074
- and any cmd-options will be appended after the matched arg.
1069
+ - the `'insert_kwargs_after'` key which its value must match one of ``*args``
1070
+ and any cmd-options will be appended after the matched arg.
1075
1071
1076
1072
Examples::
1077
1073
@@ -1149,7 +1145,7 @@ def _prepare_ref(self, ref: AnyStr) -> bytes:
1149
1145
# required for command to separate refs on stdin, as bytes
1150
1146
if isinstance (ref , bytes ):
1151
1147
# Assume 40 bytes hexsha - bin-to-ascii for some reason returns bytes, not text
1152
- refstr = ref .decode ('ascii' ) # type: str
1148
+ refstr : str = ref .decode ('ascii' )
1153
1149
elif not isinstance (ref , str ):
1154
1150
refstr = str (ref ) # could be ref-object
1155
1151
else :
0 commit comments