diff --git a/mypy.ini b/mypy.ini index 9ab1c91..25d4dec 100644 --- a/mypy.ini +++ b/mypy.ini @@ -3,11 +3,14 @@ pretty = True show_error_context = True show_column_numbers = True show_error_end = True -warn_redundant_casts = True -warn_unused_ignores = True + check_untyped_defs = True + +# see https://mypy.readthedocs.io/en/stable/error_code_list2.html +warn_redundant_casts = True strict_equality = True -enable_error_code = possibly-undefined +warn_unused_ignores = True +enable_error_code = deprecated,redundant-expr,possibly-undefined,truthy-bool,truthy-iterable,ignore-without-code,unused-awaitable # an example of suppressing # [mypy-my.config.repos.pdfannots.pdfannots] diff --git a/src/cachew/__init__.py b/src/cachew/__init__.py index 9ec332c..1a88500 100644 --- a/src/cachew/__init__.py +++ b/src/cachew/__init__.py @@ -808,7 +808,7 @@ def cached_items(): new_hash: SourceHash = json.dumps(new_hash_d) logger.debug(f'new hash: {new_hash}') - marshall = CachewMarshall(Type_=cls) + marshall: CachewMarshall[Any] = CachewMarshall(Type_=cls) with BackendCls(cache_path=db_path, logger=logger) as backend: old_hash = backend.get_old_hash() diff --git a/src/cachew/legacy.py b/src/cachew/legacy.py index 63ae886..b296a87 100644 --- a/src/cachew/legacy.py +++ b/src/cachew/legacy.py @@ -158,7 +158,7 @@ def python_type(self): def process_literal_param(self, value, dialect): raise NotImplementedError() # make pylint happy - def process_result_value(self, value: Optional[str], dialect) -> Optional[date]: # type: ignore + def process_result_value(self, value: Optional[str], dialect) -> Optional[date]: # type: ignore[explicit-override,override] res = super().process_result_value(value, dialect) if res is None: return None @@ -246,6 +246,7 @@ def strip_optional(cls) -> tuple[type, bool]: def strip_generic(tp): """ + >>> from typing import List >>> strip_generic(List[int]) >>> strip_generic(str) @@ -345,7 +346,7 @@ def make(tp: type[NT], name: Optional[str] = None) -> 'NTBinder[NT]': span = sum(f.span for f in fields) + (1 if optional else 0) return NTBinder( name=name, - type_=tp, + type_=tp, # type: ignore[arg-type] span=span, primitive=primitive, optional=optional, @@ -455,17 +456,17 @@ def flatten(self, level=0): def test_mypy_annotations() -> None: # mypy won't handle, so this has to be dynamic vs = [] - for t in Types.__args__: # type: ignore + for t in Types.__args__: # type: ignore[attr-defined] (arg,) = t.__args__ vs.append(arg) def types(ts): return sorted(ts, key=lambda t: str(t)) - assert types(vs) == types(Values.__args__) # type: ignore + assert types(vs) == types(Values.__args__) # type: ignore[attr-defined] for p in PRIMITIVE_TYPES: - assert p in Values.__args__ # type: ignore + assert p in Values.__args__ # type: ignore[attr-defined] @parametrize( diff --git a/src/cachew/tests/marshall.py b/src/cachew/tests/marshall.py index c1a5cdf..9e3fe52 100644 --- a/src/cachew/tests/marshall.py +++ b/src/cachew/tests/marshall.py @@ -115,11 +115,11 @@ def union_hook(data, type_): for i in range(count): jsons[i] = to_json(objects[i]) - strs: list[bytes] = [None for _ in range(count)] # type: ignore + strs: list[bytes] = [None for _ in range(count)] # type: ignore[misc] with profile(test_name + ':json_dump'), timer(f'json dump {count} objects of type {Type}'): for i in range(count): # TODO any orjson options to speed up? - strs[i] = orjson.dumps(jsons[i]) # pylint: disable=no-member + strs[i] = orjson.dumps(jsons[i]) db = Path('/tmp/cachew_test/db.sqlite') if db.parent.exists(): @@ -132,7 +132,7 @@ def union_hook(data, type_): conn.executemany('INSERT INTO data (value) VALUES (?)', [(s,) for s in strs]) conn.close() - strs2: list[bytes] = [None for _ in range(count)] # type: ignore + strs2: list[bytes] = [None for _ in range(count)] # type: ignore[misc] with profile(test_name + ':sqlite_load'), timer(f'sqlite load {count} objects of type {Type}'): with sqlite3.connect(db) as conn: i = 0 @@ -148,7 +148,7 @@ def union_hook(data, type_): for s in strs: fw.write(s + b'\n') - strs3: list[bytes] = [None for _ in range(count)] # type: ignore + strs3: list[bytes] = [None for _ in range(count)] # type: ignore[misc] with profile(test_name + ':jsonl_load'), timer(f'jsonl load {count} objects of type {Type}'): i = 0 with cache.open('rb') as fr: @@ -163,7 +163,7 @@ def union_hook(data, type_): with profile(test_name + ':json_load'), timer(f'json load {count} objects of type {Type}'): for i in range(count): # TODO any orjson options to speed up? - jsons2[i] = orjson.loads(strs2[i]) # pylint: disable=no-member + jsons2[i] = orjson.loads(strs2[i]) objects2 = [None for _ in range(count)] with profile(test_name + ':deserialize'), timer(f'deserializing {count} objects of type {Type}'): diff --git a/src/cachew/tests/test_cachew.py b/src/cachew/tests/test_cachew.py index e8b4ded..0313c6b 100644 --- a/src/cachew/tests/test_cachew.py +++ b/src/cachew/tests/test_cachew.py @@ -186,7 +186,7 @@ def inner(_it, _timer{init}): _t1 = _timer() return _t1 - _t0, retval """ - timeit.template = template # type: ignore + timeit.template = template # type: ignore[attr-defined] timer = timeit.Timer(lambda: len(list(data()))) t, cnt = cast(tuple[float, int], timer.timeit(number=1)) @@ -973,7 +973,7 @@ def orig2(): settings.THROW_ON_ERROR = throw with ctx: - fun = cachew(cache_path=lambda: 1 + 'bad_path_provider')(orig) # type: ignore + fun = cachew(cache_path=lambda: 1 + 'bad_path_provider')(orig) # type: ignore[arg-type,misc,operator] assert list(fun()) == [123] assert list(fun()) == [123]