From 501256708d944726b26b10728c4cc8e019365481 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Fri, 22 Oct 2021 15:40:54 +0545 Subject: [PATCH] use system hook for mypy; fix raised issues (#6851) --- .pre-commit-config.yaml | 19 +++++++------------ dvc/repo/experiments/init.py | 6 ++++-- dvc/scm/git/backend/dulwich/__init__.py | 2 +- dvc/scm/git/backend/gitpython.py | 9 +++++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ef675bbc8..4abb83318 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ ci: - skip: [pylint, dvc-pre-commit] + skip: [mypy, pylint, dvc-pre-commit] repos: - hooks: @@ -34,19 +34,14 @@ repos: - flake8-string-format repo: https://gitlab.com/pycqa/flake8 rev: 3.9.2 - - hooks: - - id: mypy - language_version: python3 - files: ^dvc/ - additional_dependencies: - - types-requests - - types-paramiko - - types-tabulate - - types-toml - repo: https://github.com/pre-commit/mirrors-mypy - rev: 'v0.910-1' - repo: local hooks: + - id: mypy + name: mypy + entry: mypy + files: ^dvc/ + language: system + types: [python] - id: pylint name: pylint entry: pylint diff --git a/dvc/repo/experiments/init.py b/dvc/repo/experiments/init.py index d06073726..7c24b8e86 100644 --- a/dvc/repo/experiments/init.py +++ b/dvc/repo/experiments/init.py @@ -85,8 +85,10 @@ def _prompts(keys: Iterable[str], defaults: Dict[str, OptStr]): else: prompt_cls = SkippablePrompt kwargs = {"default": defaults[key]} if key in defaults else {} - prompt = PROMPTS.get(key) - value = prompt_cls.ask(prompt, console=ui.error_console, **kwargs) + prompt = PROMPTS[key] + value = prompt_cls.ask( # type: ignore[call-overload] + prompt, console=ui.error_console, **kwargs + ) yield key, value diff --git a/dvc/scm/git/backend/dulwich/__init__.py b/dvc/scm/git/backend/dulwich/__init__.py index d4344d9e8..84bfd2f4f 100644 --- a/dvc/scm/git/backend/dulwich/__init__.py +++ b/dvc/scm/git/backend/dulwich/__init__.py @@ -85,7 +85,7 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method from .asyncssh_vendor import AsyncSSHVendor # monkeypatch dulwich client's default SSH vendor to use asyncssh - client.get_ssh_vendor = AsyncSSHVendor + client.get_ssh_vendor = AsyncSSHVendor # type: ignore[assignment] # Dulwich progress will return messages equivalent to git CLI, # our pbars should just display the messages as formatted by dulwich diff --git a/dvc/scm/git/backend/gitpython.py b/dvc/scm/git/backend/gitpython.py index 2c790a295..e9b245aea 100644 --- a/dvc/scm/git/backend/gitpython.py +++ b/dvc/scm/git/backend/gitpython.py @@ -148,7 +148,8 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method rev: Optional[str] = None, shallow_branch: Optional[str] = None, ): - import git + from git import Repo + from git.exc import GitCommandError ld_key = "LD_LIBRARY_PATH" @@ -170,7 +171,7 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method url = f"file://{url}" with TqdmGit(desc="Cloning", unit="obj") as pbar: clone_from = partial( - git.Repo.clone_from, + Repo.clone_from, url, to_path, env=env, # needed before we can fix it in __init__ @@ -182,7 +183,7 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method else: tmp_repo = clone_from(branch=shallow_branch, depth=1) tmp_repo.close() - except git.exc.GitCommandError as exc: # pylint: disable=no-member + except GitCommandError as exc: # pylint: disable=no-member raise CloneError(url, to_path) from exc # NOTE: using our wrapper to make sure that env is fixed in __init__ @@ -191,7 +192,7 @@ class GitPythonBackend(BaseGitBackend): # pylint:disable=abstract-method if rev: try: repo.checkout(rev) - except git.exc.GitCommandError as exc: # pylint: disable=no-member + except GitCommandError as exc: # pylint: disable=no-member raise RevError( "failed to access revision '{}' for repo '{}'".format( rev, url