From ac39679ce170c5eb21f98ac23ac0358850e8974f Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 19 Jul 2021 16:55:03 +0100 Subject: Make types in refs compatible with previous --- git/cmd.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index dd887a18..11c02afe 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -15,7 +15,6 @@ from subprocess import ( PIPE ) import subprocess -import sys import threading from textwrap import dedent @@ -539,7 +538,7 @@ class Git(LazyMixin): return self def __next__(self) -> bytes: - return self.next() + return next(self) def next(self) -> bytes: line = self.readline() @@ -799,10 +798,7 @@ class Git(LazyMixin): if kill_after_timeout: raise GitCommandError(redacted_command, '"kill_after_timeout" feature is not supported on Windows.') else: - if sys.version_info[0] > 2: - cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable - else: - cmd_not_found_exception = OSError + cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable # end handle stdout_sink = (PIPE @@ -1070,8 +1066,8 @@ class Git(LazyMixin): It contains key-values for the following: - the :meth:`execute()` kwds, as listed in :var:`execute_kwargs`; - "command options" to be converted by :meth:`transform_kwargs()`; - - the `'insert_kwargs_after'` key which its value must match one of ``*args``, - and any cmd-options will be appended after the matched arg. + - the `'insert_kwargs_after'` key which its value must match one of ``*args`` + and any cmd-options will be appended after the matched arg. Examples:: -- cgit v1.2.1 From 9e5e969479ec6018e1ba06b95bcdefca5b0082a4 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 19 Jul 2021 19:10:45 +0100 Subject: Change remaining type comments to py3.6+ types --- git/cmd.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index 11c02afe..4d0e5cdd 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -565,11 +565,11 @@ class Git(LazyMixin): .git directory in case of bare repositories.""" super(Git, self).__init__() self._working_dir = expand_path(working_dir) - self._git_options = () # type: Union[List[str], Tuple[str, ...]] - self._persistent_git_options = [] # type: List[str] + self._git_options: Union[List[str], Tuple[str, ...]] = () + self._persistent_git_options: List[str] = [] # Extra environment variables to pass to git commands - self._environment = {} # type: Dict[str, str] + self._environment: Dict[str, str] = {} # cached command slots self.cat_file_header = None @@ -603,9 +603,9 @@ class Git(LazyMixin): process_version = self._call_process('version') # should be as default *args and **kwargs used version_numbers = process_version.split(' ')[2] - self._version_info = tuple( + self._version_info: Tuple[int, int, int, int] = tuple( int(n) for n in version_numbers.split('.')[:4] if n.isdigit() - ) # type: Tuple[int, int, int, int] # type: ignore + ) # type: ignore # use typeguard here else: super(Git, self)._set_cache_(attr) # END handle version info @@ -868,8 +868,8 @@ class Git(LazyMixin): # Wait for the process to return status = 0 - stdout_value = b'' # type: Union[str, bytes] - stderr_value = b'' # type: Union[str, bytes] + stdout_value: Union[str, bytes] = b'' + stderr_value: Union[str, bytes] = b'' newline = "\n" if universal_newlines else b"\n" try: if output_stream is None: @@ -1145,7 +1145,7 @@ class Git(LazyMixin): # required for command to separate refs on stdin, as bytes if isinstance(ref, bytes): # Assume 40 bytes hexsha - bin-to-ascii for some reason returns bytes, not text - refstr = ref.decode('ascii') # type: str + refstr: str = ref.decode('ascii') elif not isinstance(ref, str): refstr = str(ref) # could be ref-object else: -- cgit v1.2.1 From 017b0d4b19127868ccb8ee616f64734b48f6e620 Mon Sep 17 00:00:00 2001 From: Yobmod Date: Mon, 19 Jul 2021 20:08:07 +0100 Subject: Add a cast to git.cmd _version_info --- git/cmd.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'git/cmd.py') diff --git a/git/cmd.py b/git/cmd.py index 4d0e5cdd..4404981e 100644 --- a/git/cmd.py +++ b/git/cmd.py @@ -603,19 +603,19 @@ class Git(LazyMixin): process_version = self._call_process('version') # should be as default *args and **kwargs used version_numbers = process_version.split(' ')[2] - self._version_info: Tuple[int, int, int, int] = tuple( - int(n) for n in version_numbers.split('.')[:4] if n.isdigit() - ) # type: ignore # use typeguard here + self._version_info = cast(Tuple[int, int, int, int], + tuple(int(n) for n in version_numbers.split('.')[:4] if n.isdigit()) + ) else: super(Git, self)._set_cache_(attr) # END handle version info - @property + @ property def working_dir(self) -> Union[None, PathLike]: """:return: Git directory we are working on""" return self._working_dir - @property + @ property def version_info(self) -> Tuple[int, int, int, int]: """ :return: tuple(int, int, int, int) tuple with integers representing the major, minor @@ -623,7 +623,7 @@ class Git(LazyMixin): This value is generated on demand and is cached""" return self._version_info - @overload + @ overload def execute(self, command: Union[str, Sequence[Any]], *, @@ -631,7 +631,7 @@ class Git(LazyMixin): ) -> 'AutoInterrupt': ... - @overload + @ overload def execute(self, command: Union[str, Sequence[Any]], *, @@ -640,7 +640,7 @@ class Git(LazyMixin): ) -> Union[str, Tuple[int, str, str]]: ... - @overload + @ overload def execute(self, command: Union[str, Sequence[Any]], *, @@ -649,7 +649,7 @@ class Git(LazyMixin): ) -> Union[bytes, Tuple[int, bytes, str]]: ... - @overload + @ overload def execute(self, command: Union[str, Sequence[Any]], *, @@ -659,7 +659,7 @@ class Git(LazyMixin): ) -> str: ... - @overload + @ overload def execute(self, command: Union[str, Sequence[Any]], *, -- cgit v1.2.1