← Winnitude! Search  ·  Reader Mode (1020 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 13 LINKS

Mypy linting issue with Repo.clone_from and progress bar · gitpython-developers/GitPython · Discussion #2002

Repository navigation

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 Feb 7, 2025 · 1 comment Return to top Discussion options

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:

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?

1 You must be logged in to vote

Replies: 1 comment

Comment options

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.

1 You must be logged in to vote 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 Converted from issue

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