Skip to content

Commit 527425c

Browse files
committed
add pyright task to tox and fix pyright errors
1 parent fa89e78 commit 527425c

File tree

6 files changed

+56
-24
lines changed

6 files changed

+56
-24
lines changed

.editorconfig

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ max_line_length = 88
1313
[.travis.yml]
1414
indent_style = space
1515
indent_size = 2
16+
17+
[*.json]
18+
charset = utf-8
19+
indent_style = space
20+
indent_size = 2
21+
max_line_length = 88

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.1
2+
3+
Fix type hints
4+
15
## 0.5.0
26

37
Switched the minio-py client library version from `<7` to `>=7`.

minio_storage/policy.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ def bucket(
2626
return pol
2727

2828

29-
def _none(bucket_name: str) -> T.Dict:
29+
def _none(bucket_name: str) -> T.Dict[str, T.Any]:
3030
return {"Version": "2012-10-17", "Statement": []}
3131

3232

33-
def _get(bucket_name: str) -> T.Dict:
33+
def _get(bucket_name: str) -> T.Dict[str, T.Any]:
3434
return {
3535
"Version": "2012-10-17",
3636
"Statement": [
@@ -44,7 +44,7 @@ def _get(bucket_name: str) -> T.Dict:
4444
}
4545

4646

47-
def _read(bucket_name: str) -> T.Dict:
47+
def _read(bucket_name: str) -> T.Dict[str, T.Any]:
4848
return {
4949
"Version": "2012-10-17",
5050
"Statement": [
@@ -70,7 +70,7 @@ def _read(bucket_name: str) -> T.Dict:
7070
}
7171

7272

73-
def _write(bucket_name: str) -> T.Dict:
73+
def _write(bucket_name: str) -> T.Dict[str, T.Any]:
7474
return {
7575
"Version": "2012-10-17",
7676
"Statement": [
@@ -101,7 +101,7 @@ def _write(bucket_name: str) -> T.Dict:
101101
}
102102

103103

104-
def _read_write(bucket_name: str) -> T.Dict:
104+
def _read_write(bucket_name: str) -> T.Dict[str, T.Any]:
105105
return {
106106
"Version": "2012-10-17",
107107
"Statement": [

minio_storage/storage.py

+13-18
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
import mimetypes
33
import posixpath
44
import typing as T
5-
import urllib
65
from logging import getLogger
7-
from urllib.parse import urlsplit, urlunsplit
6+
from urllib.parse import quote, urlsplit, urlunsplit
87

98
import minio
109
import minio.error as merr
@@ -119,10 +118,6 @@ def _create_base_url_client(client: minio.Minio, bucket_name: str, base_url: str
119118
region=client._get_region(bucket_name, None),
120119
http_client=client._http,
121120
)
122-
if hasattr(client, "_credentials"):
123-
# Client credentials do not exist prior to minio-py 5.0.7, but
124-
# they should be reused if possible
125-
base_url_client._credentials = client._credentials
126121

127122
return base_url_client
128123

@@ -154,7 +149,7 @@ def _open(self, name, mode="rb"):
154149
raise minio_error(f"File {name} could not be saved: {str(e)}", e)
155150
return f
156151

157-
def _save(self, name: str, content: bytes) -> str:
152+
def _save(self, name: str, content: T.BinaryIO) -> str:
158153
try:
159154
if hasattr(content, "seek") and callable(content.seek):
160155
content.seek(0)
@@ -212,16 +207,15 @@ def exists(self, name: str) -> bool:
212207
return True
213208
except merr.InvalidResponseError as error:
214209
# TODO - deprecate
215-
if error.code == "NoSuchKey":
210+
if error._code == "NoSuchKey":
216211
return False
217212
else:
218213
raise minio_error(f"Could not stat file {name}", error)
219214
except merr.S3Error:
220215
return False
221-
except merr.S3Error:
222-
raise
223216
except Exception as error:
224217
logger.error(error)
218+
return False
225219

226220
def listdir(self, path: str) -> T.Tuple[T.List, T.List]:
227221
# [None, "", "."] is supported to mean the configured root among various
@@ -263,7 +257,7 @@ def size(self, name: str) -> int:
263257

264258
def _presigned_url(
265259
self, name: str, max_age: T.Optional[datetime.timedelta] = None
266-
) -> str:
260+
) -> T.Optional[str]:
267261
kwargs = {}
268262
if max_age is not None:
269263
kwargs["expires"] = max_age
@@ -293,11 +287,14 @@ def _presigned_url(
293287
url_parts.fragment,
294288
)
295289
)
296-
return url
290+
if url:
291+
return str(url)
292+
return None
297293

298294
def url(
299295
self, name: str, *args, max_age: T.Optional[datetime.timedelta] = None
300-
) -> str:
296+
) -> T.Optional[str]:
297+
url = ""
301298
if self.presign_urls:
302299
url = self._presigned_url(name, max_age=max_age)
303300
else:
@@ -313,14 +310,12 @@ def strip_end(path):
313310
return path
314311

315312
if self.base_url is not None:
316-
url = "{}/{}".format(
317-
strip_end(self.base_url), urllib.parse.quote(strip_beg(name))
318-
)
313+
url = "{}/{}".format(strip_end(self.base_url), quote(strip_beg(name)))
319314
else:
320315
url = "{}/{}/{}".format(
321316
strip_end(self.endpoint_url),
322317
self.bucket_name,
323-
urllib.parse.quote(strip_beg(name)),
318+
quote(strip_beg(name)),
324319
)
325320
return url
326321

@@ -353,7 +348,7 @@ def modified_time(self, name: str) -> datetime.datetime:
353348
_NoValue = object()
354349

355350

356-
def get_setting(name, default=_NoValue):
351+
def get_setting(name: str, default=_NoValue) -> T.Any:
357352
result = getattr(settings, name, default)
358353
if result is _NoValue:
359354
# print("Attr {} : {}".format(name, getattr(settings, name, default)))

pyrightconfig.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"include": [
3+
"minio_storage",
4+
"tests"
5+
],
6+
"exclude": [
7+
"**/migrations"
8+
],
9+
"reportMissingImports": true,
10+
"reportMissingTypeStubs": false,
11+
"strictParameterNoneValue": false,
12+
"reportInvalidStringEscapeSequence": "warning",
13+
"reportUnboundVariable": "warning",
14+
"reportOptionalMemberAccess": "warning",
15+
"reportOptionalIterable": "warning",
16+
"pythonVersion": "3.8",
17+
"pythonPlatform": "Linux"
18+
}

tox.ini

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ python =
1010
3.8: py38
1111
3.9: py39
1212
3.10: py310
13-
3.11: py311, lint, docs
13+
3.11: py311, lint, docs, pyright
1414

1515

1616
[testenv]
@@ -40,6 +40,15 @@ commands =
4040
coverage html
4141
depends=py311-django42-minioknown
4242

43+
[testenv:pyright]
44+
basepython = python3.11
45+
deps =
46+
pyright
47+
-rdev-requirements.txt
48+
commands =
49+
pyright --skipunannotated --level WARNING
50+
51+
4352
[testenv:lint]
4453
setenv=
4554
PYTHONWARNINGS=ignore

0 commit comments

Comments
 (0)