Skip to content

Commit ccc8f2b

Browse files
codexByron
authored andcommitted
Address review feedback and restore CI compatibility
The Python package workflow failed during import on Python 3.7 and 3.8 because subprocess.Popen was subscripted in an eagerly evaluated annotation. It also reported mypy errors caused by the invariant IterableList type variable and an overly narrow IndexFileSHA1Writer stream type; lint reported an unused IO import. Quote review feedback: IterableList variance no longer matched its subtype comment; the shutil.rmtree callback was narrower than the typeshed contract; and expand_path overloads omitted None and pathlib.Path results and did not handle Path.resolve exceptions consistently. Restore covariance and the IO[bytes] stream type, quote the Popen annotation for old Python runtimes, correct rmtree callback types, and make expand_path return and exception behavior match the implementation. Update the cwd annotation that now correctly flows from expand_path. This addresses the review feedback and restores the lint and mypy checks.
1 parent 4f30206 commit ccc8f2b

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

git/cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ def execute(
13581358

13591359
# Allow the user to have the command executed in their working dir.
13601360
try:
1361-
cwd = self._working_dir or os.getcwd() # type: Union[None, str]
1361+
cwd = self._working_dir or os.getcwd() # type: Optional[PathLike]
13621362
if not os.access(str(cwd), os.X_OK):
13631363
cwd = None
13641364
except FileNotFoundError:

git/util.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106

107107
# ---------------------------------------------------------------------
108108

109-
T_IterableObj = TypeVar("T_IterableObj", bound=Union["IterableObj", "Has_id_attribute"])
109+
T_IterableObj = TypeVar("T_IterableObj", bound=Union["IterableObj", "Has_id_attribute"], covariant=True)
110110
# So IterableList[Head] is subtype of IterableList[IterableObj].
111111

112112
_logger = logging.getLogger(__name__)
@@ -217,7 +217,7 @@ def rmtree(path: PathLike) -> None:
217217
couldn't be deleted are read-only. Windows will not remove them in that case.
218218
"""
219219

220-
def handler(function: Callable[[PathLike], Any], path: PathLike, _excinfo: Any) -> None:
220+
def handler(function: Callable[[str], Any], path: str, _excinfo: Any) -> None:
221221
"""Callback for :func:`shutil.rmtree`.
222222
223223
This works as either a ``onexc`` or ``onerror`` style callback.
@@ -508,7 +508,7 @@ def get_user_id() -> str:
508508
return "%s@%s" % (getpass.getuser(), platform.node())
509509

510510

511-
def finalize_process(proc: Union[subprocess.Popen[Any], "Git.AutoInterrupt"], **kwargs: Any) -> None:
511+
def finalize_process(proc: Union["subprocess.Popen[Any]", "Git.AutoInterrupt"], **kwargs: Any) -> None:
512512
"""Wait for the process (clone, fetch, pull or push) and handle its errors
513513
accordingly."""
514514
# TODO: No close proc-streams??
@@ -520,17 +520,17 @@ def expand_path(p: None, expand_vars: bool = ...) -> None: ...
520520

521521

522522
@overload
523-
def expand_path(p: PathLike, expand_vars: bool = ...) -> str:
523+
def expand_path(p: PathLike, expand_vars: bool = ...) -> Optional[PathLike]:
524524
# TODO: Support for Python 3.5 has been dropped, so these overloads can be improved.
525525
...
526526

527527

528528
def expand_path(p: Union[None, PathLike], expand_vars: bool = True) -> Optional[PathLike]:
529529
if p is None:
530530
return None
531-
if isinstance(p, Path):
532-
return p.resolve()
533531
try:
532+
if isinstance(p, Path):
533+
return p.resolve()
534534
expanded_path = osp.expanduser(os.fspath(p))
535535
if expand_vars:
536536
expanded_path = osp.expandvars(expanded_path)
@@ -986,7 +986,7 @@ class IndexFileSHA1Writer:
986986

987987
__slots__ = ("f", "sha1")
988988

989-
def __init__(self, f: BinaryIO) -> None:
989+
def __init__(self, f: IO[bytes]) -> None:
990990
self.f = f
991991
self.sha1 = make_sha(b"")
992992

0 commit comments

Comments
 (0)