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 optionsjdumas 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
Can you help me understand what's wrong here? Missing typing info on the gitpython side? |
Replies: 1 comment
Comment optionspick7 Jul 26, 2026
|
Nothing is wrong with the runtime use here. This is a typing mismatch in the current public signature.
progress: CallableProgress = None and So mypy is following the annotation, while the runtime accepts the older 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 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 |
This discussion was converted from issue #2001 on February 08, 2025 15:12.