mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-12 07:18:23 +01:00
Fix typechecking errors around a few places (#4945)
This commit is contained in:
Vendored
+5
-2
@@ -3,6 +3,7 @@ import json
|
||||
import logging
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from copy import copy
|
||||
from typing import Optional
|
||||
|
||||
from funcy import decorator
|
||||
from shortuuid import uuid
|
||||
@@ -16,7 +17,9 @@ from dvc.exceptions import (
|
||||
DvcException,
|
||||
)
|
||||
from dvc.progress import Tqdm
|
||||
from dvc.remote.slow_link_detection import slow_link_guard
|
||||
from dvc.remote.slow_link_detection import ( # type: ignore[attr-defined]
|
||||
slow_link_guard,
|
||||
)
|
||||
|
||||
from ..tree.base import RemoteActionNotImplemented
|
||||
|
||||
@@ -41,7 +44,7 @@ class CloudCache:
|
||||
"""Cloud cache class."""
|
||||
|
||||
DEFAULT_CACHE_TYPES = ["copy"]
|
||||
CACHE_MODE = None
|
||||
CACHE_MODE: Optional[int] = None
|
||||
|
||||
def __init__(self, tree):
|
||||
self.tree = tree
|
||||
|
||||
@@ -4,7 +4,7 @@ import tempfile
|
||||
import threading
|
||||
from contextlib import contextmanager
|
||||
from distutils.dir_util import copy_tree
|
||||
from typing import Iterable
|
||||
from typing import Dict, Iterable
|
||||
|
||||
from funcy import cached_property, reraise, retry, wrap_with
|
||||
|
||||
@@ -73,8 +73,8 @@ def external_repo(url, rev=None, for_write=False, **kwargs):
|
||||
_remove(path)
|
||||
|
||||
|
||||
CLONES = {}
|
||||
CACHE_DIRS = {}
|
||||
CLONES: Dict[str, str] = {}
|
||||
CACHE_DIRS: Dict[str, str] = {}
|
||||
|
||||
|
||||
def clean_repos():
|
||||
|
||||
+8
-5
@@ -1,19 +1,22 @@
|
||||
from collections import OrderedDict
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Dict, Optional
|
||||
|
||||
HASH_DIR_SUFFIX = ".dir"
|
||||
|
||||
DirInfo = Dict[str, str]
|
||||
|
||||
|
||||
@dataclass
|
||||
class HashInfo:
|
||||
PARAM_SIZE = "size"
|
||||
PARAM_NFILES = "nfiles"
|
||||
|
||||
name: str
|
||||
value: str
|
||||
dir_info: dict = field(default=None, compare=False)
|
||||
size: int = field(default=None, compare=False)
|
||||
nfiles: int = field(default=None, compare=False)
|
||||
name: Optional[str]
|
||||
value: Optional[str]
|
||||
dir_info: Optional[DirInfo] = field(default=None, compare=False)
|
||||
size: Optional[int] = field(default=None, compare=False)
|
||||
nfiles: Optional[int] = field(default=None, compare=False)
|
||||
|
||||
def __bool__(self):
|
||||
return bool(self.value)
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
import os
|
||||
import pathlib
|
||||
import posixpath
|
||||
from typing import Callable
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from funcy import cached_property
|
||||
@@ -253,7 +254,7 @@ class CloudURLInfo(URLInfo):
|
||||
|
||||
|
||||
class HTTPURLInfo(URLInfo):
|
||||
__hash__ = URLInfo.__hash__
|
||||
__hash__: Callable[["HTTPURLInfo"], int] = URLInfo.__hash__
|
||||
|
||||
def __init__(self, url):
|
||||
p = urlparse(url)
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ class Base:
|
||||
self._root_dir = os.path.realpath(root_dir)
|
||||
|
||||
@property
|
||||
def root_dir(self):
|
||||
def root_dir(self) -> str:
|
||||
return self._root_dir
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ class Git(Base):
|
||||
self.files_to_track = set()
|
||||
|
||||
@property
|
||||
def root_dir(self):
|
||||
def root_dir(self) -> str:
|
||||
return self.repo.working_tree_dir
|
||||
|
||||
@staticmethod
|
||||
|
||||
@@ -133,11 +133,11 @@ class Stage(params.StageParams):
|
||||
self.desc = desc
|
||||
|
||||
@property
|
||||
def path(self):
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@path.setter
|
||||
def path(self, path):
|
||||
def path(self, path: str):
|
||||
self._path = path
|
||||
self.__dict__.pop("path_in_repo", None)
|
||||
self.__dict__.pop("relpath", None)
|
||||
@@ -169,7 +169,7 @@ class Stage(params.StageParams):
|
||||
return f"stage: '{self.addressing}'"
|
||||
|
||||
@property
|
||||
def addressing(self):
|
||||
def addressing(self) -> str:
|
||||
"""
|
||||
Useful for alternative presentations where we don't need
|
||||
`Stage:` prefix.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from collections import OrderedDict
|
||||
from functools import partial
|
||||
from operator import attrgetter
|
||||
from typing import TYPE_CHECKING, List
|
||||
from typing import TYPE_CHECKING, List, no_type_check
|
||||
|
||||
from funcy import post_processing
|
||||
|
||||
@@ -57,6 +57,7 @@ def _serialize_out(out):
|
||||
return out.def_path if not flags else {out.def_path: flags}
|
||||
|
||||
|
||||
@no_type_check
|
||||
def _serialize_outs(outputs: List[BaseOutput]):
|
||||
outs, metrics, plots = [], [], []
|
||||
for out in sort_by_path(outputs):
|
||||
@@ -95,6 +96,7 @@ def _serialize_params_keys(params):
|
||||
return keys
|
||||
|
||||
|
||||
@no_type_check
|
||||
def _serialize_params_values(params: List[ParamsDependency]):
|
||||
"""Returns output of following format, used for lockfile:
|
||||
{'params.yaml': {'lr': '1', 'train': 2}, {'params2.yaml': {'lr': '1'}}
|
||||
|
||||
Reference in New Issue
Block a user