Skip to content

Commit fb5d584

Browse files
authored
Merge pull request #2187 from pick7/codex/remote-progress-return-type
Improve RemoteProgress parse return typing
2 parents 951cc44 + 28e2114 commit fb5d584

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

git/util.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,17 @@ def __init__(self) -> None:
620620
self.error_lines: List[str] = []
621621
self.other_lines: List[str] = []
622622

623-
def _parse_progress_line(self, line: AnyStr) -> None:
623+
def _parse_progress_line(self, line: AnyStr) -> Optional[object]:
624624
"""Parse progress information from the given line as retrieved by
625625
:manpage:`git-push(1)` or :manpage:`git-fetch(1)`.
626626
627627
- Lines that do not contain progress info are stored in :attr:`other_lines`.
628628
- Lines that seem to contain an error (i.e. start with ``error:`` or ``fatal:``)
629629
are stored in :attr:`error_lines`.
630+
631+
The base implementation returns ``None``. Subclasses may return another
632+
value for compatibility with existing overrides, but callers should treat
633+
the return value as unspecified.
630634
"""
631635
# handle
632636
# Counting objects: 4, done.
@@ -641,7 +645,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
641645

642646
if self._cur_line.startswith(("error:", "fatal:")):
643647
self.error_lines.append(self._cur_line)
644-
return
648+
return None
645649

646650
cur_count, max_count = None, None
647651
match = self.re_op_relative.match(line_str)
@@ -651,7 +655,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
651655
if not match:
652656
self.line_dropped(line_str)
653657
self.other_lines.append(line_str)
654-
return
658+
return None
655659
# END could not get match
656660

657661
op_code = 0
@@ -682,7 +686,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
682686
self.line_dropped(line_str)
683687
# Note: Don't add this line to the other lines, as we have to silently
684688
# drop it.
685-
return
689+
return None
686690
# END handle op code
687691

688692
# Figure out stage.
@@ -708,6 +712,7 @@ def _parse_progress_line(self, line: AnyStr) -> None:
708712
max_count and float(max_count),
709713
message,
710714
)
715+
return None
711716

712717
def new_message_handler(self) -> Callable[[str], None]:
713718
"""
@@ -717,7 +722,7 @@ def new_message_handler(self) -> Callable[[str], None]:
717722
"""
718723

719724
def handler(line: AnyStr) -> None:
720-
return self._parse_progress_line(line.rstrip())
725+
self._parse_progress_line(line.rstrip())
721726

722727
# END handler
723728

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# This module is part of GitPython and is released under the
2+
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/
3+
4+
"""Tests for static characteristics of remote progress helpers."""
5+
6+
from typing import AnyStr
7+
8+
from git import RemoteProgress
9+
10+
11+
def test_parse_progress_line_override_can_return_non_none() -> None:
12+
"""Subclass overrides may return a value without violating base typing."""
13+
14+
class ReturningProgress(RemoteProgress):
15+
def _parse_progress_line(self, line: AnyStr) -> str:
16+
super()._parse_progress_line(line)
17+
return "handled"
18+
19+
assert ReturningProgress()._parse_progress_line("unmatched progress") == "handled"

0 commit comments

Comments
 (0)