GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — RemoteProgress._parse_progress_line may merit a broader return type · Issue #1834 · gitpython-developers/GitPython

RemoteProgress._parse_progress_line may merit a broader return type #1834

New issue
Copy link
New issue
Copy link
Closed
Feature
#2187
Closed
RemoteProgress._parse_progress_line may merit a broader return type#1834
Feature
#2187
Copy link
Labels
acknowledgedhelp wanted

Description

@EliahKagan
EliahKagan
opened on Feb 20, 2024
Issue body actions

RemoteProgress._parse_progress_line is conceptually a "protected" method: code outside GitPython may subclass RemoteProgress and override it with another implementation (which may also reasonably call the base class implementation).

The method is conceptually void as implemented in the base class, always implicitly returning None, and it is annotated accordingly:

GitPython/git/util.py

Line 582 in afa5754

def _parse_progress_line(self, line: AnyStr) -> None:

However, while it would not ordinarily be useful to do so, it is--or has been--also intended that it be overridable to return a non-None value. This is mostly for compatibility with existing code that may have done so in the past, but it may be that reasonable cases for doing so in new code can still arise. This is reflected in code of GitPython:

GitPython/git/util.py

Lines 685 to 697 in afa5754

def new_message_handler(self) -> Callable[[str], None]:
"""
:return:
A progress handler suitable for handle_process_output(), passing lines on to
this Progress handler in a suitable format
"""
def handler(line: AnyStr) -> None:
return self._parse_progress_line(line.rstrip())
# END handler
return handler

And in the subclass of RemoteProgress introduced in the test suite, which overrides the method:

GitPython/test/test_remote.py

Lines 54 to 59 in afa5754

def _parse_progress_line(self, line):
# We may remove the line later if it is dropped.
# Keep it for debugging.
self._seen_lines.append(line)
rval = super()._parse_progress_line(line)
return rval

But any override that returns a non-None value is currently inconsistent with the return type annotation on the base class, which is written as -> None. For Liskov substitutability, an overridden method's return type must be the same or a subclass of the base method's return type, and if a subclass has type annotations, and the return type is specified as a non-Any type, type checkers such as mypy and pyright will report a non-None return type as a violation.

If possible, the return type in RemoteProgress should be broadened, but in a way that does not unduly encourage subclasses to return non-None. See comments on #1788, starting at #1788 (comment), for a discussion and analysis of this. This issue, and the above recommendation, is based on the findings and discussion there.

Activity

  1. Byron
    added
    acknowledged
    help wanted
    on Feb 21, 2024
  2. Byron
    added the
    Feature
    issue type on Jul 20, 2026
  3. Byron
    closed this as completedin #2187on Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedhelp wanted

    Type

    Feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.