mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
fix mypy errors; add mypy precommit hooks (#5237)
This commit is contained in:
@@ -19,6 +19,12 @@ repos:
|
||||
- flake8-string-format
|
||||
repo: https://gitlab.com/pycqa/flake8
|
||||
rev: 3.8.4
|
||||
- hooks:
|
||||
- id: mypy
|
||||
language_version: python3
|
||||
files: ^dvc/
|
||||
repo: https://github.com/pre-commit/mirrors-mypy
|
||||
rev: 'v0.790'
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: pylint
|
||||
|
||||
+14
-4
@@ -1,5 +1,6 @@
|
||||
import logging
|
||||
import os
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import colorama
|
||||
|
||||
@@ -14,20 +15,29 @@ from ..repo.scm_context import scm_context
|
||||
from ..utils import LARGE_DIR_SIZE, glob_targets, resolve_paths
|
||||
from . import locked
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from dvc.types import TargetType
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@locked
|
||||
@scm_context
|
||||
def add(
|
||||
repo, targets, recursive=False, no_commit=False, fname=None, **kwargs,
|
||||
repo,
|
||||
targets: "TargetType",
|
||||
recursive=False,
|
||||
no_commit=False,
|
||||
fname=None,
|
||||
**kwargs,
|
||||
):
|
||||
from dvc.utils.collections import ensure_list
|
||||
|
||||
if recursive and fname:
|
||||
raise RecursiveAddingWhileUsingFilename()
|
||||
|
||||
if isinstance(targets, str):
|
||||
targets = [targets]
|
||||
|
||||
targets = ensure_list(targets)
|
||||
link_failures = []
|
||||
stages_list = []
|
||||
num_targets = len(targets)
|
||||
|
||||
@@ -14,6 +14,7 @@ from dvc.utils.serialize import LOADERS, ParseError
|
||||
if TYPE_CHECKING:
|
||||
from dvc.output.base import BaseOutput
|
||||
from dvc.repo import Repo
|
||||
from dvc.types import DvcPath
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -26,7 +27,7 @@ def _is_params(dep: "BaseOutput"):
|
||||
return isinstance(dep, ParamsDependency)
|
||||
|
||||
|
||||
def _collect_configs(repo: "Repo", rev, targets=None) -> List[PathInfo]:
|
||||
def _collect_configs(repo: "Repo", rev, targets=None) -> List["DvcPath"]:
|
||||
params, path_infos = collect(
|
||||
repo,
|
||||
targets=targets or [],
|
||||
|
||||
@@ -50,9 +50,10 @@ class Plots:
|
||||
Data parsing is postponed, since it's affected by props.
|
||||
"""
|
||||
from dvc.tree.repo import RepoTree
|
||||
from dvc.utils.collections import ensure_list
|
||||
|
||||
targets = [targets] if isinstance(targets, str) else targets or []
|
||||
data = {}
|
||||
targets = ensure_list(targets)
|
||||
data: Dict[str, Dict] = {}
|
||||
for rev in self.repo.brancher(revs=revs):
|
||||
# .brancher() adds unwanted workspace
|
||||
if revs is not None and rev not in revs:
|
||||
@@ -121,18 +122,18 @@ class Plots:
|
||||
|
||||
def show(
|
||||
self,
|
||||
targets=None,
|
||||
targets: List[str] = None,
|
||||
revs=None,
|
||||
props=None,
|
||||
templates=None,
|
||||
recursive=False,
|
||||
):
|
||||
from dvc.utils.collections import ensure_list
|
||||
|
||||
data = self.collect(targets, revs, recursive)
|
||||
|
||||
# If any mentioned plot doesn't have any data then that's an error
|
||||
targets = [targets] if isinstance(targets, str) else targets or []
|
||||
for target in targets:
|
||||
for target in ensure_list(targets):
|
||||
rpath = relpath(target, self.repo.root_dir)
|
||||
if not any(
|
||||
"data" in rev_data[key]
|
||||
|
||||
@@ -37,6 +37,7 @@ from .utils import (
|
||||
logger = logging.getLogger(__name__)
|
||||
# Disallow all punctuation characters except hyphen and underscore
|
||||
INVALID_STAGENAME_CHARS = set(string.punctuation) - {"_", "-"}
|
||||
Env = Dict[str, str]
|
||||
|
||||
|
||||
def loads_from(cls, repo, path, wdir, data):
|
||||
@@ -252,8 +253,8 @@ class Stage(params.StageParams):
|
||||
return any(out.checkpoint for out in self.outs)
|
||||
|
||||
@property
|
||||
def env(self) -> Dict[str, str]:
|
||||
env = {}
|
||||
def env(self) -> Env:
|
||||
env: Env = {}
|
||||
for out in self.outs:
|
||||
if any(out.env.keys() and env.keys()):
|
||||
raise DvcException("Duplicated env variable")
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
from typing import TYPE_CHECKING, Optional, Union
|
||||
from typing import TYPE_CHECKING, List, Optional, Union
|
||||
|
||||
from dvc.path_info import PathInfo, URLInfo
|
||||
|
||||
@@ -10,3 +10,4 @@ DvcPath = Union[PathInfo, URLInfo]
|
||||
AnyPath = Union[str, DvcPath, StrPath]
|
||||
|
||||
OptStr = Optional[str]
|
||||
TargetType = Union[List[str], str]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from collections.abc import Mapping
|
||||
from typing import Iterable, List, Union
|
||||
|
||||
from pygtrie import StringTrie as _StringTrie
|
||||
|
||||
@@ -57,3 +58,11 @@ def apply_diff(src, dest):
|
||||
src.__class__.__name__, dest.__class__.__name__
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def ensure_list(item: Union[Iterable[str], str, None]) -> List[str]:
|
||||
if item is None:
|
||||
return []
|
||||
if isinstance(item, str):
|
||||
return [item]
|
||||
return list(item)
|
||||
|
||||
Reference in New Issue
Block a user