Skip to content

Commit f1be75c

Browse files
committed
lint: fix type hints, pylint issues
1 parent a14c076 commit f1be75c

File tree

12 files changed

+45
-36
lines changed

12 files changed

+45
-36
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ files = ["src", "tests"]
7070
[[tool.mypy.overrides]]
7171
module = [
7272
"pygtrie",
73+
"dvc_http.*",
7374
"funcy",
7475
"git",
7576
"gitdb.*",

src/scmrepo/git/backend/dulwich/__init__.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, repo, name, mode, sha):
5151
self._mode = mode
5252
self._sha = sha
5353

54-
def open(
54+
def open( # pylint: disable=unused-argument
5555
self,
5656
mode: str = "r",
5757
encoding: Optional[str] = None,
@@ -153,18 +153,18 @@ def encoding(self) -> str:
153153
return self._config.encoding
154154
return self._config.backends[0].encoding
155155

156-
def get(self, section: Tuple[str], name: str) -> str:
156+
def get(self, section: Tuple[str, ...], name: str) -> str:
157157
"""Return the specified setting as a string."""
158158
return self._config.get(section, name).decode(self.encoding)
159159

160-
def get_bool(self, section: Tuple[str], name: str) -> bool:
160+
def get_bool(self, section: Tuple[str, ...], name: str) -> bool:
161161
"""Return the specified setting as a boolean."""
162162
value = self._config.get_boolean(section, name)
163163
if value is None:
164164
raise ValueError("setting is not a valid boolean")
165165
return value
166166

167-
def get_multivar(self, section: Tuple[str], name: str) -> Iterator[str]:
167+
def get_multivar(self, section: Tuple[str, ...], name: str) -> Iterator[str]:
168168
"""Iterate over string values in the specified multivar setting."""
169169
for value in self._config.get_multivar(section, name):
170170
yield value.decode(self.encoding)

src/scmrepo/git/backend/pygit2/__init__.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from io import BytesIO, StringIO, TextIOWrapper
77
from typing import (
88
TYPE_CHECKING,
9-
Any,
109
Callable,
1110
Dict,
1211
Generator,
@@ -55,7 +54,7 @@ def open(
5554
self,
5655
mode: str = "r",
5756
encoding: str = None,
58-
key: tuple = None,
57+
key: Optional[Tuple[str, ...]] = None,
5958
raw: bool = True,
6059
rev: Optional[str] = None,
6160
**kwargs,
@@ -67,14 +66,16 @@ def open(
6766
if self.backend is not None:
6867
try:
6968
if rev:
69+
# pylint: disable-next=protected-access
7070
commit, _ref = self.backend._resolve_refish(rev)
7171
else:
7272
pass
7373
if raw:
7474
blob_kwargs = {}
7575
else:
76+
assert key is not None
7677
path = "/".join(key)
77-
blob_kwargs: Dict[str, Any] = {
78+
blob_kwargs = {
7879
"as_path": path,
7980
"commit_id": commit.oid,
8081
}
@@ -123,21 +124,21 @@ class Pygit2Config(Config):
123124
def __init__(self, config: "_Pygit2Config"):
124125
self._config = config
125126

126-
def _key(self, section: Tuple[str], name: str) -> str:
127+
def _key(self, section: Tuple[str, ...], name: str) -> str:
127128
return ".".join(section + (name,))
128129

129-
def get(self, section: Tuple[str], name: str) -> str:
130+
def get(self, section: Tuple[str, ...], name: str) -> str:
130131
return self._config[self._key(section, name)]
131132

132-
def get_bool(self, section: Tuple[str], name: str) -> bool:
133+
def get_bool(self, section: Tuple[str, ...], name: str) -> bool:
133134
from pygit2 import GitError
134135

135136
try:
136137
return self._config.get_bool(self._key(section, name))
137138
except GitError as exc:
138139
raise ValueError("invalid boolean config entry") from exc
139140

140-
def get_multivar(self, section: Tuple[str], name: str) -> Iterator[str]:
141+
def get_multivar(self, section: Tuple[str, ...], name: str) -> Iterator[str]:
141142
from pygit2 import GitError
142143

143144
try:

src/scmrepo/git/backend/pygit2/filter.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LFSFilter(Filter):
1515

1616
def __init__(self, *args, **kwargs):
1717
self._smudge_buf: Optional[io.BytesIO] = None
18-
self._smudge_git_dir: Optional[str] = None
18+
self._smudge_root: Optional[str] = None
1919

2020
def check(self, src: "FilterSource", attr_values: List[str]):
2121
if attr_values[0] == "lfs":
@@ -48,6 +48,7 @@ def _smudge(self, write_next: Callable[[bytes], None]):
4848
from scmrepo.git.lfs import smudge
4949
from scmrepo.git.lfs.fetch import get_fetch_url
5050

51+
assert self._smudge_buf is not None
5152
self._smudge_buf.seek(0)
5253
with Git(self._smudge_root) as scm:
5354
try:

src/scmrepo/git/config.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ class Config(ABC):
1010
"""Read-only Git config."""
1111

1212
@abstractmethod
13-
def get(self, section: Tuple[str], name: str) -> str:
13+
def get(self, section: Tuple[str, ...], name: str) -> str:
1414
"""Return the specified setting as a string.
1515
1616
Raises:
1717
KeyError: Option was not set.
1818
"""
1919

2020
@abstractmethod
21-
def get_bool(self, section: Tuple[str], name: str) -> bool:
21+
def get_bool(self, section: Tuple[str, ...], name: str) -> bool:
2222
"""Return the specified setting as a boolean.
2323
2424
Raises:
@@ -27,7 +27,7 @@ def get_bool(self, section: Tuple[str], name: str) -> bool:
2727
"""
2828

2929
@abstractmethod
30-
def get_multivar(self, section: Tuple[str], name: str) -> Iterator[str]:
30+
def get_multivar(self, section: Tuple[str, ...], name: str) -> Iterator[str]:
3131
"""Iterate over string values in the specified multivar setting.
3232
3333
Raises:

src/scmrepo/git/lfs/client.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
from contextlib import AbstractContextManager
33
from functools import wraps
4-
from typing import TYPE_CHECKING, Any, Coroutine, Dict, Iterable, Optional
4+
from typing import TYPE_CHECKING, Any, Awaitable, Callable, Dict, Iterable, Optional
55

66
import aiohttp
77
from dvc_http import HTTPFileSystem
@@ -27,9 +27,10 @@
2727

2828
class _LFSClient(ReadOnlyRetryClient):
2929
async def _request(self, *args, **kwargs):
30-
return await super()._request(*args, **kwargs)
30+
return await super()._request(*args, **kwargs) # pylint: disable=no-member
3131

3232

33+
# pylint: disable=abstract-method
3334
class _LFSFileSystem(HTTPFileSystem):
3435
def __init__(self, *args, **kwargs):
3536
super().__init__(*args, **kwargs)
@@ -71,10 +72,11 @@ async def get_client(self, **kwargs):
7172
return ReadOnlyRetryClient(**kwargs)
7273

7374

74-
def _authed(f: Coroutine):
75+
def _authed(f: Callable[..., Awaitable]):
7576
"""Set credentials and retry the given coroutine if needed."""
7677

77-
@wraps(f)
78+
# pylint: disable=protected-access
79+
@wraps(f) # type: ignore[arg-type]
7880
async def wrapper(self, *args, **kwargs):
7981
try:
8082
return await f(self, *args, **kwargs)
@@ -110,7 +112,7 @@ def __init__(
110112
"""
111113
self.url = url
112114
self.git_url = git_url
113-
self.headers = {}
115+
self.headers: Dict[str, str] = headers or {}
114116

115117
def __exit__(self, *args, **kwargs):
116118
self.close()

src/scmrepo/git/lfs/fetch.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fnmatch
22
import io
33
import os
4-
from typing import TYPE_CHECKING, Callable, Iterable, Iterator, List, Optional
4+
from typing import TYPE_CHECKING, Callable, Iterable, Iterator, List, Optional, Set
55

66
from scmrepo.exceptions import InvalidRemote, SCMError
77

@@ -24,7 +24,7 @@ def fetch(
2424
# NOTE: This currently does not support fetching objects from the worktree
2525
if not revs:
2626
revs = ["HEAD"]
27-
objects = set()
27+
objects: Set[Pointer] = set()
2828
for rev in revs:
2929
objects.update(
3030
pointer
@@ -82,6 +82,7 @@ def get_fetch_url(scm: "Git", remote: Optional[str] = None): # noqa: C901
8282
remote = "origin"
8383

8484
# check remote.*.lfsurl (can be set in git config and .lfsconfig)
85+
assert remote is not None
8586
try:
8687
return git_config.get(("remote", remote), "lfsurl")
8788
except KeyError:
@@ -156,6 +157,6 @@ def _filter_paths(
156157
help="Refs or commits to fetch. Defaults to 'HEAD'.",
157158
)
158159
args = parser.parse_args()
159-
with Git(".") as scm:
160+
with Git(".") as scm_: # pylint: disable=E0601
160161
print("fetch: fetching reference", ", ".join(args.refs), file=sys.stderr)
161-
fetch(scm, revs=args.refs, remote=args.remote)
162+
fetch(scm_, revs=args.refs, remote=args.remote)

src/scmrepo/git/lfs/pointer.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414

1515

1616
def _get_kv(line: str) -> Tuple[str, str]:
17-
return line.strip().split(maxsplit=1)
17+
key, value = line.strip().split(maxsplit=1)
18+
return key, value
1819

1920

2021
@dataclass
@@ -41,8 +42,9 @@ def build(cls, fobj: BinaryIO) -> "Pointer":
4142
def load(cls, fobj: IO) -> "Pointer":
4243
"""Load the specified pointer file."""
4344

44-
if isinstance(fobj, io.TextIOBase):
45-
text_obj: TextIO = fobj
45+
if isinstance(fobj, io.TextIOBase): # type: ignore[unreachable]
46+
text_obj: TextIO = fobj # type: ignore[unreachable]
47+
4648
else:
4749
text_obj = io.TextIOWrapper(fobj, encoding="utf-8")
4850

@@ -102,6 +104,6 @@ def to_bytes(self) -> bytes:
102104
sys.exit("Nothing to do")
103105

104106
print(f"Git LFS pointer for {args.file}\n", file=sys.stderr)
105-
with open(args.file, mode="rb") as fobj:
106-
p = Pointer.build(fobj)
107+
with open(args.file, mode="rb") as fobj_:
108+
p = Pointer.build(fobj_)
107109
print(p.dump(), end="")

src/scmrepo/git/lfs/progress.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ def _update_git(self):
3535

3636
def branch(
3737
self,
38-
path_1: "Union[str, BinaryIO]",
38+
path_1: Union[str, BinaryIO],
3939
path_2: str,
4040
kwargs: Dict[str, Any],
4141
child: Optional[Callback] = None,
4242
):
4343
if child:
44-
child = child
44+
pass
4545
elif self.git_progress:
4646
child = TqdmCallback(
4747
bytes=True, desc=path_1 if isinstance(path_1, str) else path_2

src/scmrepo/git/lfs/smudge.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def smudge(
1414
storage: "LFSStorage", fobj: BinaryIO, url: Optional[str] = None
1515
) -> BinaryIO:
1616
"""Wrap the specified binary IO stream and run LFS smudge if necessary."""
17-
reader = io.BufferedReader(fobj)
17+
reader = io.BufferedReader(fobj) # type: ignore[arg-type]
1818
data = reader.peek(100)
1919
if any(data.startswith(header) for header in HEADERS):
2020
# read the pointer data into memory since the raw stream is unseekable
@@ -45,7 +45,7 @@ def smudge(
4545
)
4646
scm = Git()
4747
try:
48-
with smudge(scm.lfs_storage, sys.stdin.buffer) as fobj:
49-
sys.stdout.buffer.write(fobj.read())
48+
with smudge(scm.lfs_storage, sys.stdin.buffer) as fobj_:
49+
sys.stdout.buffer.write(fobj_.read())
5050
finally:
5151
scm.close()

src/scmrepo/git/lfs/storage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def open(
4444
oid = obj if isinstance(obj, str) else obj.oid
4545
path = self.oid_to_path(oid)
4646
try:
47-
return open(path, **kwargs)
47+
return open(path, **kwargs) # pylint: disable=unspecified-encoding
4848
except FileNotFoundError:
4949
if not fetch_url or not isinstance(obj, Pointer):
5050
raise
@@ -54,7 +54,7 @@ def open(
5454
raise FileNotFoundError(
5555
errno.ENOENT, os.strerror(errno.ENOENT), path
5656
) from exc
57-
return open(path, **kwargs)
57+
return open(path, **kwargs) # pylint: disable=unspecified-encoding
5858

5959
def close(self):
6060
pass

tests/test_lfs.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=redefined-outer-name
12
import io
23

34
import pytest

0 commit comments

Comments
 (0)