diff --git a/dvc/_debug.py b/dvc/_debug.py index 75b9a0022..9751beb90 100644 --- a/dvc/_debug.py +++ b/dvc/_debug.py @@ -14,7 +14,7 @@ def viztracer_profile( log_async: bool = False, ): try: - import viztracer + import viztracer # ty: ignore[unresolved-import] except ImportError: print("Failed to run profiler, viztracer is not installed") # noqa: T201 yield @@ -37,7 +37,7 @@ def yappi_profile( separate_threads: Optional[bool] = False, ): try: - import yappi + import yappi # ty: ignore[unresolved-import] except ImportError: print("Failed to run profiler, yappi is not installed") # noqa: T201 yield @@ -79,7 +79,7 @@ def yappi_profile( def instrument(html_output=False): """Run a statistical profiler""" try: - from pyinstrument import Profiler + from pyinstrument import Profiler # ty: ignore[unresolved-import] except ImportError: print("Failed to run profiler, pyinstrument is not installed") # noqa: T201 yield @@ -123,7 +123,7 @@ def debug(): yield except Exception: try: - import ipdb as pdb # noqa: T100 + import ipdb as pdb # noqa: T100 # ty: ignore[unresolved-import] except ImportError: import pdb # type: ignore[no-redef] # noqa: T100 pdb.post_mortem() diff --git a/dvc/analytics.py b/dvc/analytics.py index 4badcb2cb..988457243 100644 --- a/dvc/analytics.py +++ b/dvc/analytics.py @@ -71,6 +71,7 @@ def send(path): thus, the need of removing such file afterwards. """ import requests + from requests.exceptions import RequestException url = os.environ.get(DVC_ANALYTICS_ENDPOINT, "https://analytics.dvc.org") headers = {"content-type": "application/json"} @@ -85,7 +86,7 @@ def send(path): try: requests.post(url, json=report, headers=headers, timeout=5) - except requests.exceptions.RequestException as e: + except RequestException as e: logger.trace("", exc_info=True) logger.debug("failed to send analytics report %s", str(e)) diff --git a/dvc/daemon.py b/dvc/daemon.py index 432cc2ce5..406d1b21b 100644 --- a/dvc/daemon.py +++ b/dvc/daemon.py @@ -32,10 +32,10 @@ def _win_detached_subprocess(args: Sequence[str], **kwargs) -> int: assert os.name == "nt" from subprocess import ( # type: ignore[attr-defined] - CREATE_NEW_PROCESS_GROUP, - CREATE_NO_WINDOW, - STARTF_USESHOWWINDOW, - STARTUPINFO, + CREATE_NEW_PROCESS_GROUP, # ty: ignore[unresolved-import] + CREATE_NO_WINDOW, # ty: ignore[unresolved-import] + STARTF_USESHOWWINDOW, # ty: ignore[unresolved-import] + STARTUPINFO, # ty: ignore[unresolved-import] ) # https://stackoverflow.com/a/7006424 diff --git a/dvc/dagascii.py b/dvc/dagascii.py index f8623ffe5..6d20ed42e 100644 --- a/dvc/dagascii.py +++ b/dvc/dagascii.py @@ -195,7 +195,7 @@ def _build_sugiyama_layout(vertices, edges): sug.yspace = VertexViewer.HEIGHT sug.xspace = minw - sug.route_edge = route_with_lines + sug.route_edge = route_with_lines # ty: ignore[unresolved-attribute] sug.draw() diff --git a/dvc/fs/callbacks.py b/dvc/fs/callbacks.py index d30ad4f24..590530085 100644 --- a/dvc/fs/callbacks.py +++ b/dvc/fs/callbacks.py @@ -1,8 +1,8 @@ from contextlib import ExitStack from typing import TYPE_CHECKING, BinaryIO, Optional, Union -import fsspec from fsspec.callbacks import DEFAULT_CALLBACK, Callback # noqa: F401 +from fsspec.callbacks import TqdmCallback as _TqdmCallback from dvc.progress import Tqdm from dvc.utils.objects import cached_property @@ -14,7 +14,7 @@ if TYPE_CHECKING: from dvc.ui._rich_progress import RichTransferProgress -class TqdmCallback(fsspec.callbacks.TqdmCallback): +class TqdmCallback(_TqdmCallback): def __init__( self, size: Optional[int] = None, diff --git a/dvc/fs/dvc_path.py b/dvc/fs/dvc_path.py index 1a181f8b2..9de54e473 100644 --- a/dvc/fs/dvc_path.py +++ b/dvc/fs/dvc_path.py @@ -15,7 +15,7 @@ Examples from urllib.parse import urlsplit -from upath import UPath +from upath import UPath # ty: ignore[unresolved-import] class DVCPath(UPath): diff --git a/dvc/repo/collect.py b/dvc/repo/collect.py index 31805e950..37829786f 100644 --- a/dvc/repo/collect.py +++ b/dvc/repo/collect.py @@ -43,13 +43,13 @@ def _collect_paths( def _filter_outs( - outs: Outputs, fs_paths: StrPaths, duplicates=False + repo: "Repo", outs: Outputs, fs_paths: StrPaths, duplicates=False ) -> tuple[Outputs, StrPaths]: res_outs: Outputs = [] fs_res_paths = fs_paths for out in outs: - fs_path = out.repo.dvcfs.from_os_path(out.fs_path) + fs_path = repo.dvcfs.from_os_path(out.fs_path) if fs_path in fs_paths: res_outs.append(out) if not duplicates: @@ -77,4 +77,4 @@ def collect( target_paths = _collect_paths(repo, targets, recursive=recursive) - return _filter_outs(outs, target_paths, duplicates=duplicates) + return _filter_outs(repo, outs, target_paths, duplicates=duplicates) diff --git a/dvc/repo/experiments/utils.py b/dvc/repo/experiments/utils.py index 45cb76d99..e1038d541 100644 --- a/dvc/repo/experiments/utils.py +++ b/dvc/repo/experiments/utils.py @@ -2,7 +2,7 @@ import os import random import sys from collections import defaultdict -from collections.abc import Generator, Iterable, Mapping +from collections.abc import Generator, Iterable, Mapping, Sequence from functools import wraps from typing import TYPE_CHECKING, Callable, Optional, Union @@ -126,7 +126,7 @@ def iter_remote_refs(scm: "Git", url: str, base: Optional[str] = None, **kwargs) def push_refspec( scm: "Git", url: str, - push_list=list[tuple[Optional[str], str]], + push_list: Sequence[tuple[Optional[str], str]], force: bool = False, on_diverged: Optional[Callable[[str, str], bool]] = None, **kwargs, diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index 30813e9e4..6fcf3b828 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -346,14 +346,14 @@ def _get_data_targets(definitions: dict): def infer_data_sources(plot_id, config=None): - y = config.get("y", None) + y = config.get("y", None) if config else None if isinstance(y, dict): sources = list(y.keys()) else: sources = [plot_id] - x = config.get("x", None) + x = config.get("x", None) if config else None if isinstance(x, dict): sources.append(first(x.keys())) @@ -507,7 +507,7 @@ def _collect_pipeline_files(repo, targets: list[str], props, onerror=None): @error_handler def _collect_definitions( repo: "Repo", - targets=None, + targets: list[str], props: Optional[dict] = None, onerror: Optional[Callable] = None, **kwargs, diff --git a/dvc/repo/worktree.py b/dvc/repo/worktree.py index 7b8e95637..992d1e339 100644 --- a/dvc/repo/worktree.py +++ b/dvc/repo/worktree.py @@ -152,7 +152,7 @@ def _merge_push_meta( # noqa: C901 else: if entry.hash_info: out.hash_info = entry.hash_info - if out.meta.version_id is None: + if out.meta is None or out.meta.version_id is None: out.meta = entry.meta if out.meta: out.meta.remote = remote @@ -181,7 +181,7 @@ def _update_worktree_out( ): from dvc_data.index import build - remote_name = out.remote or out.meta.remote + remote_name = out.remote or (out.meta.remote if out.meta is not None else None) if not remote_name: logger.warning("Could not update '%s', it was never pushed to a remote", out) return @@ -212,11 +212,12 @@ def _update_worktree_out( logger.warning("Could not update '%s', directory is empty in the remote", out) return - _fetch_out_changes(out, local_index, remote_index, remote) + _fetch_out_changes(repo, out, local_index, remote_index, remote) _update_out_meta(repo, out, local_index, remote_index, remote) def _fetch_out_changes( + repo: "Repo", out: "Output", local_index: Union["DataIndex", "DataIndexView"], remote_index: Union["DataIndex", "DataIndexView"], @@ -242,7 +243,7 @@ def _fetch_out_changes( cb.set_size(total) apply( diff, - out.repo.root_dir, + repo.root_dir, out.fs, update_meta=False, storage="data", diff --git a/dvc/stage/serialize.py b/dvc/stage/serialize.py index fef6514b7..6cd8b4b0e 100644 --- a/dvc/stage/serialize.py +++ b/dvc/stage/serialize.py @@ -168,6 +168,7 @@ def to_single_stage_lockfile(stage: "Stage", **kwargs) -> dict: for f in _serialize_tree_obj_to_files(obj) ] else: + assert item.meta is not None meta_d = item.meta.to_dict() meta_d.pop("isdir", None) ret.update(_serialize_hi_to_dict(item.hash_info)) diff --git a/dvc/testing/benchmarks/fixtures.py b/dvc/testing/benchmarks/fixtures.py index 32a05d878..7d2ca14a9 100644 --- a/dvc/testing/benchmarks/fixtures.py +++ b/dvc/testing/benchmarks/fixtures.py @@ -158,7 +158,7 @@ def make_bench(request): # pytest >= 8.4.0 wrapped_func = fixture_function._get_wrapped_function() except AttributeError: - wrapped_func = fixture_function.__pytest_wrapped__.obj + wrapped_func = fixture_function.__pytest_wrapped__.obj # ty: ignore[unresolved-attribute] assert inspect.isgeneratorfunction(wrapped_func) generator = wrapped_func(request) diff --git a/dvc/ui/pager.py b/dvc/ui/pager.py index 0fc2c1c07..28cfdb2a7 100644 --- a/dvc/ui/pager.py +++ b/dvc/ui/pager.py @@ -44,6 +44,7 @@ def prepare_default_pager( def make_pager(cmd=None): def _pager(text): + assert cmd return pydoc.tempfilepager(pydoc.plain(text), cmd) return _pager if cmd else pydoc.plainpager diff --git a/dvc/updater.py b/dvc/updater.py index 179e65783..ffe3a6b2f 100644 --- a/dvc/updater.py +++ b/dvc/updater.py @@ -99,13 +99,14 @@ class Updater: import json import requests + from requests.exceptions import RequestException url = os.environ.get(DVC_UPDATER_ENDPOINT, self.URL) logger.debug("Checking updates in %s", url) try: resp = requests.get(url, timeout=self.TIMEOUT_GET) info = resp.json() - except requests.exceptions.RequestException as exc: + except RequestException as exc: logger.trace("", exc_info=True) logger.debug("Failed to retrieve latest version: %s", exc) return diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index d8dc31afc..ee0575212 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -8,6 +8,7 @@ import sys from typing import TYPE_CHECKING, Optional import colorama +from colorama import AnsiToWin32 if TYPE_CHECKING: from typing import TextIO @@ -205,7 +206,7 @@ def boxify(message, border_color=None): def _visual_width(line): """Get the number of columns required to display a string""" - return len(re.sub(colorama.ansitowin32.AnsiToWin32.ANSI_CSI_RE, "", line)) + return len(re.sub(AnsiToWin32.ANSI_CSI_RE, "", line)) def _visual_center(line, width):