Skip to content

Commit 96c4365

Browse files
committed
flake8 and mypy fixes
1 parent f62c8d8 commit 96c4365

File tree

2 files changed

+20
-30
lines changed

2 files changed

+20
-30
lines changed

git/cmd.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# typing ---------------------------------------------------------------------------
4444

4545
from typing import (Any, AnyStr, BinaryIO, Callable, Dict, IO, List, Mapping,
46-
Sequence, TYPE_CHECKING, Tuple, Union, cast, overload)
46+
Sequence, TYPE_CHECKING, TextIO, Tuple, Union, cast, overload)
4747

4848
from git.types import PathLike, Literal, TBD
4949

@@ -98,14 +98,17 @@ def handle_process_output(process: subprocess.Popen,
9898
or if decoding must happen later (i.e. for Diffs).
9999
"""
100100
# Use 2 "pump" threads and wait for both to finish.
101-
def pump_stream(cmdline: str, name: str, stream: BinaryIO, is_decode: bool,
102-
handler: Union[None, Callable[[str], None]]) -> None:
101+
def pump_stream(cmdline: str, name: str, stream: Union[BinaryIO, TextIO], is_decode: bool,
102+
handler: Union[None, Callable[[Union[bytes, str]], None]]) -> None:
103103
try:
104104
for line in stream:
105105
if handler:
106106
if is_decode:
107+
assert isinstance(line, bytes)
107108
line_str = line.decode(defenc)
108-
handler(line_str)
109+
handler(line_str)
110+
else:
111+
handler(line)
109112
except Exception as ex:
110113
log.error("Pumping %r of cmd(%s) failed due to: %r", name, remove_password_if_present(cmdline), ex)
111114
raise CommandError(['<%s-pump>' % name] + remove_password_if_present(cmdline), ex) from ex
@@ -337,12 +340,12 @@ def is_cygwin(cls) -> bool:
337340

338341
@overload
339342
@classmethod
340-
def polish_url(cls, url: str, is_cygwin: Union[None, bool] = None) -> str:
343+
def polish_url(cls, url: str, is_cygwin: Literal[False] = ...) -> str:
341344
...
342345

343346
@overload
344347
@classmethod
345-
def polish_url(cls, url: PathLike, is_cygwin: Union[None, bool] = None) -> PathLike:
348+
def polish_url(cls, url: PathLike, is_cygwin: Union[None, bool] = None) -> str:
346349
...
347350

348351
@classmethod
@@ -628,16 +631,16 @@ def version_info(self) -> Tuple[int, int, int, int]:
628631
def execute(self,
629632
command: Union[str, Sequence[Any]],
630633
*,
631-
as_process: Literal[True],
632-
) -> AutoInterrupt:
634+
as_process: Literal[True]
635+
) -> 'AutoInterrupt':
633636
...
634637

635638
@overload
636639
def execute(self,
637640
command: Union[str, Sequence[Any]],
638641
*,
639642
as_process: Literal[False] = False,
640-
stdout_as_string: Literal[True],
643+
stdout_as_string: Literal[True]
641644
) -> Union[str, Tuple[int, str, str]]:
642645
...
643646

@@ -646,7 +649,7 @@ def execute(self,
646649
command: Union[str, Sequence[Any]],
647650
*,
648651
as_process: Literal[False] = False,
649-
stdout_as_string: Literal[False] = False,
652+
stdout_as_string: Literal[False] = False
650653
) -> Union[bytes, Tuple[int, bytes, str]]:
651654
...
652655

@@ -656,8 +659,7 @@ def execute(self,
656659
*,
657660
with_extended_output: Literal[False],
658661
as_process: Literal[False],
659-
stdout_as_string: Literal[True],
660-
662+
stdout_as_string: Literal[True]
661663
) -> str:
662664
...
663665

@@ -667,8 +669,7 @@ def execute(self,
667669
*,
668670
with_extended_output: Literal[False],
669671
as_process: Literal[False],
670-
stdout_as_string: Literal[False],
671-
672+
stdout_as_string: Literal[False]
672673
) -> bytes:
673674
...
674675

@@ -829,16 +830,13 @@ def execute(self,
829830
creationflags=PROC_CREATIONFLAGS,
830831
**subprocess_kwargs
831832
)
832-
proc = cast(Popen[bytes], proc)
833833

834-
proc.stdout = cast(BinaryIO, proc.stdout)
835834
except cmd_not_found_exception as err:
836835
raise GitCommandNotFound(redacted_command, err) from err
837836
else:
838-
assert isinstance(proc.stdout, BinaryIO)
839-
assert isinstance(proc.stderr, BinaryIO)
840-
# proc.stdout = cast(BinaryIO, proc.stdout)
841-
# proc.stderr = cast(BinaryIO, proc.stderr)
837+
proc = cast(Popen, proc)
838+
proc.stdout = cast(BinaryIO, proc.stdout)
839+
proc.stderr = cast(BinaryIO, proc.stderr)
842840

843841
if as_process:
844842
return self.AutoInterrupt(proc, command)
@@ -1164,6 +1162,8 @@ def _prepare_ref(self, ref: AnyStr) -> bytes:
11641162
refstr = ref.decode('ascii') # type: str
11651163
elif not isinstance(ref, str):
11661164
refstr = str(ref) # could be ref-object
1165+
else:
1166+
refstr = ref
11671167

11681168
if not refstr.endswith("\n"):
11691169
refstr += "\n"

git/util.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,16 +281,6 @@ def _cygexpath(drive: Optional[str], path: PathLike) -> str:
281281
) # type: Tuple[Tuple[Pattern[str], Callable, bool], ...]
282282

283283

284-
@overload
285-
def cygpath(path: str) -> str:
286-
...
287-
288-
289-
@overload
290-
def cygpath(path: PathLike) -> PathLike:
291-
...
292-
293-
294284
def cygpath(path: PathLike) -> PathLike:
295285
"""Use :meth:`git.cmd.Git.polish_url()` instead, that works on any environment."""
296286
path = str(path) # ensure is str and not AnyPath.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy