mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
fix some, suppress some issues from ty check (#10841)
This commit is contained in:
+4
-4
@@ -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()
|
||||
|
||||
+2
-1
@@ -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))
|
||||
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
+1
-1
@@ -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()
|
||||
|
||||
|
||||
+2
-2
@@ -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,
|
||||
|
||||
+1
-1
@@ -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):
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
+2
-1
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user