Skip to content

Commit ec50706

Browse files
committed
Add warn_return_any=True and use typing.cast() if needed
1 parent d747087 commit ec50706

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

mypy.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ disallow_untyped_decorators = True
1111
disallow_untyped_defs = True
1212
no_implicit_optional = True
1313
warn_redundant_casts = True
14+
warn_return_any = True
1415
warn_unreachable = True
1516
warn_unused_ignores = True
1617

src/apify/_memory_storage/resource_clients/base_resource_collection_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from abc import ABC, abstractmethod
44
from operator import itemgetter
5-
from typing import TYPE_CHECKING, Generic, TypeVar
5+
from typing import TYPE_CHECKING, Generic, TypeVar, cast
66

77
from apify_shared.models import ListPage
88
from apify_shared.utils import ignore_docs
@@ -91,7 +91,8 @@ async def get_or_create(
9191
id=_id,
9292
)
9393
if found:
94-
return found._to_resource_info()
94+
resource_info = found._to_resource_info()
95+
return cast(dict, resource_info)
9596

9697
new_resource = resource_client_class(
9798
id=_id,
@@ -110,4 +111,4 @@ async def get_or_create(
110111
write_metadata=self._memory_storage_client._write_metadata,
111112
)
112113

113-
return resource_info
114+
return cast(dict, resource_info)

src/apify/_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def __get__(self: dualproperty, obj: DualPropertyOwner | None, owner: type[DualP
109109
Returns:
110110
The result of the getter.
111111
"""
112-
return self.getter(obj or owner)
112+
val = self.getter(obj or owner)
113+
return cast(DualPropertyType, val)
113114

114115

115116
@overload
@@ -337,7 +338,7 @@ def __getitem__(self: LRUCache, key: str) -> T:
337338
val = self._cache[key]
338339
# No 'key in cache' condition since the previous line would raise KeyError
339340
self._cache.move_to_end(key)
340-
return val
341+
return cast(T, val)
341342

342343
# Sadly TS impl returns bool indicating whether the key was already present or not
343344
def __setitem__(self: LRUCache, key: str, value: T) -> None:

0 commit comments

Comments
 (0)