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 — Mypy linting issue with Repo.clone_from and progress bar · gitpython-developers/GitPython · Discussion #2002

Mypy linting issue with Repo.clone_from and progress bar #2002

Unanswered
jdumas asked this question in Q&A
Mypy linting issue with Repo.clone_from and progress bar #2002
@jdumas jdumas
Feb 7, 2025 · 1 comment
Return to top
Discussion options
  • Uh oh!

    There was an error while loading. Please reload this page.

jdumas
Feb 7, 2025

Hi,

Consider the following example:

import rich.progress
import git
from git import Repo
from rich.console import Console

console = Console(log_path=False)

class GitProgressPrinter(git.RemoteProgress):
    def __init__(self, progress, name):
        super().__init__()
        self.progress = progress
        self.name = name
        self.task = progress.add_task(name)

    def update(self, op_code, cur_count, max_count=None, message=""):
        pass


def main():
    with rich.progress.Progress(console=console) as progress:
        progress_bar = GitProgressPrinter(progress, "My Repo")
        Repo.clone_from("url", "dir", progress=progress_bar, depth=1)

Using gitpython==3.1.44 and mypy==1.15.0, it shows the following message:

Image

Argument of type "GitProgressPrinter" cannot be assigned to parameter "progress" of type "CallableProgress" in function "clone_from"
  Type "GitProgressPrinter" is not assignable to type "CallableProgress"
    Type "GitProgressPrinter" is not assignable to type "(int, str | float, str | float | None, str) -> None"
    "GitProgressPrinter" is not assignable to "None"

Can you help me understand what's wrong here? Missing typing info on the gitpython side?

You must be logged in to vote
All reactions

Replies: 1 comment

Comment options
  • Uh oh!

    There was an error while loading. Please reload this page.

pick7
Jul 26, 2026

Nothing is wrong with the runtime use here. This is a typing mismatch in the current public signature.

Repo.clone_from() is annotated as:

progress: CallableProgress = None

and CallableProgress is a callable with the progress callback signature, or None. But GitPython's own docs/comments for that alias say that Repo.clone() and Repo.clone_from() also accept RemoteProgress instances, and the implementation eventually goes through the same progress parsing path that supports RemoteProgress objects.

So mypy is following the annotation, while the runtime accepts the older RemoteProgress-subclass style.

Two workarounds:

from typing import cast
from git.types import CallableProgress

Repo.clone_from(
    "url",
    "dir",
    progress=cast(CallableProgress, progress_bar),
    depth=1,
)

or, if you only need the callback shape and not the RemoteProgress parser object itself:

Repo.clone_from("url", "dir", progress=progress_bar.update, depth=1)

The first one keeps your current runtime behaviour and only tells the type checker to accept it. The longer-term fix would be to widen the clone() / clone_from() annotation so it matches the documented/runtime API, e.g. allowing RemoteProgress as well as CallableProgress.

You must be logged in to vote
All reactions
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
@jdumas @pick7
Converted from issue

This discussion was converted from issue #2001 on February 08, 2025 15:12.

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.