Skip to content

Commit a7a41bb

Browse files
committed
ci: update mypy config and fix some errors
1 parent fb3583a commit a7a41bb

File tree

5 files changed

+20
-16
lines changed

5 files changed

+20
-16
lines changed

mypy.ini

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ pretty = True
33
show_error_context = True
44
show_column_numbers = True
55
show_error_end = True
6-
warn_redundant_casts = True
7-
warn_unused_ignores = True
6+
87
check_untyped_defs = True
8+
9+
# see https://mypy.readthedocs.io/en/stable/error_code_list2.html
10+
warn_redundant_casts = True
911
strict_equality = True
10-
enable_error_code = possibly-undefined
12+
warn_unused_ignores = True
13+
enable_error_code = deprecated,redundant-expr,possibly-undefined,truthy-bool,truthy-iterable,ignore-without-code,unused-awaitable
1114

1215
# an example of suppressing
1316
# [mypy-my.config.repos.pdfannots.pdfannots]

src/cachew/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,7 @@ def cached_items():
808808
new_hash: SourceHash = json.dumps(new_hash_d)
809809
logger.debug(f'new hash: {new_hash}')
810810

811-
marshall = CachewMarshall(Type_=cls)
811+
marshall: CachewMarshall[Any] = CachewMarshall(Type_=cls)
812812

813813
with BackendCls(cache_path=db_path, logger=logger) as backend:
814814
old_hash = backend.get_old_hash()

src/cachew/legacy.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def python_type(self):
158158
def process_literal_param(self, value, dialect):
159159
raise NotImplementedError() # make pylint happy
160160

161-
def process_result_value(self, value: Optional[str], dialect) -> Optional[date]: # type: ignore
161+
def process_result_value(self, value: Optional[str], dialect) -> Optional[date]: # type: ignore[explicit-override,override]
162162
res = super().process_result_value(value, dialect)
163163
if res is None:
164164
return None
@@ -246,6 +246,7 @@ def strip_optional(cls) -> tuple[type, bool]:
246246

247247
def strip_generic(tp):
248248
"""
249+
>>> from typing import List
249250
>>> strip_generic(List[int])
250251
<class 'list'>
251252
>>> strip_generic(str)
@@ -345,7 +346,7 @@ def make(tp: type[NT], name: Optional[str] = None) -> 'NTBinder[NT]':
345346
span = sum(f.span for f in fields) + (1 if optional else 0)
346347
return NTBinder(
347348
name=name,
348-
type_=tp,
349+
type_=tp, # type: ignore[arg-type]
349350
span=span,
350351
primitive=primitive,
351352
optional=optional,
@@ -455,17 +456,17 @@ def flatten(self, level=0):
455456
def test_mypy_annotations() -> None:
456457
# mypy won't handle, so this has to be dynamic
457458
vs = []
458-
for t in Types.__args__: # type: ignore
459+
for t in Types.__args__: # type: ignore[attr-defined]
459460
(arg,) = t.__args__
460461
vs.append(arg)
461462

462463
def types(ts):
463464
return sorted(ts, key=lambda t: str(t))
464465

465-
assert types(vs) == types(Values.__args__) # type: ignore
466+
assert types(vs) == types(Values.__args__) # type: ignore[attr-defined]
466467

467468
for p in PRIMITIVE_TYPES:
468-
assert p in Values.__args__ # type: ignore
469+
assert p in Values.__args__ # type: ignore[attr-defined]
469470

470471

471472
@parametrize(

src/cachew/tests/marshall.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ def union_hook(data, type_):
115115
for i in range(count):
116116
jsons[i] = to_json(objects[i])
117117

118-
strs: list[bytes] = [None for _ in range(count)] # type: ignore
118+
strs: list[bytes] = [None for _ in range(count)] # type: ignore[misc]
119119
with profile(test_name + ':json_dump'), timer(f'json dump {count} objects of type {Type}'):
120120
for i in range(count):
121121
# TODO any orjson options to speed up?
122-
strs[i] = orjson.dumps(jsons[i]) # pylint: disable=no-member
122+
strs[i] = orjson.dumps(jsons[i])
123123

124124
db = Path('/tmp/cachew_test/db.sqlite')
125125
if db.parent.exists():
@@ -132,7 +132,7 @@ def union_hook(data, type_):
132132
conn.executemany('INSERT INTO data (value) VALUES (?)', [(s,) for s in strs])
133133
conn.close()
134134

135-
strs2: list[bytes] = [None for _ in range(count)] # type: ignore
135+
strs2: list[bytes] = [None for _ in range(count)] # type: ignore[misc]
136136
with profile(test_name + ':sqlite_load'), timer(f'sqlite load {count} objects of type {Type}'):
137137
with sqlite3.connect(db) as conn:
138138
i = 0
@@ -148,7 +148,7 @@ def union_hook(data, type_):
148148
for s in strs:
149149
fw.write(s + b'\n')
150150

151-
strs3: list[bytes] = [None for _ in range(count)] # type: ignore
151+
strs3: list[bytes] = [None for _ in range(count)] # type: ignore[misc]
152152
with profile(test_name + ':jsonl_load'), timer(f'jsonl load {count} objects of type {Type}'):
153153
i = 0
154154
with cache.open('rb') as fr:
@@ -163,7 +163,7 @@ def union_hook(data, type_):
163163
with profile(test_name + ':json_load'), timer(f'json load {count} objects of type {Type}'):
164164
for i in range(count):
165165
# TODO any orjson options to speed up?
166-
jsons2[i] = orjson.loads(strs2[i]) # pylint: disable=no-member
166+
jsons2[i] = orjson.loads(strs2[i])
167167

168168
objects2 = [None for _ in range(count)]
169169
with profile(test_name + ':deserialize'), timer(f'deserializing {count} objects of type {Type}'):

src/cachew/tests/test_cachew.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def inner(_it, _timer{init}):
186186
_t1 = _timer()
187187
return _t1 - _t0, retval
188188
"""
189-
timeit.template = template # type: ignore
189+
timeit.template = template # type: ignore[attr-defined]
190190

191191
timer = timeit.Timer(lambda: len(list(data())))
192192
t, cnt = cast(tuple[float, int], timer.timeit(number=1))
@@ -973,7 +973,7 @@ def orig2():
973973
settings.THROW_ON_ERROR = throw
974974

975975
with ctx:
976-
fun = cachew(cache_path=lambda: 1 + 'bad_path_provider')(orig) # type: ignore
976+
fun = cachew(cache_path=lambda: 1 + 'bad_path_provider')(orig) # type: ignore[arg-type,misc,operator]
977977
assert list(fun()) == [123]
978978
assert list(fun()) == [123]
979979

0 commit comments

Comments
 (0)