Skip to content

Commit

Permalink
Add warn_return_any=True and use typing.cast() if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
vdusek committed Dec 4, 2023
1 parent d747087 commit 2c85966
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ disallow_untyped_decorators = True
disallow_untyped_defs = True
no_implicit_optional = True
warn_redundant_casts = True
warn_return_any = True
warn_unreachable = True
warn_unused_ignores = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from abc import ABC, abstractmethod
from operator import itemgetter
from typing import TYPE_CHECKING, Generic, TypeVar
from typing import TYPE_CHECKING, Generic, TypeVar, cast

from apify_shared.models import ListPage
from apify_shared.utils import ignore_docs
Expand Down Expand Up @@ -91,7 +91,8 @@ async def get_or_create(
id=_id,
)
if found:
return found._to_resource_info()
resource_info = found._to_resource_info()
return cast(dict, resource_info)

new_resource = resource_client_class(
id=_id,
Expand All @@ -110,4 +111,4 @@ async def get_or_create(
write_metadata=self._memory_storage_client._write_metadata,
)

return resource_info
return cast(dict, resource_info)
5 changes: 3 additions & 2 deletions src/apify/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ def __get__(self: dualproperty, obj: DualPropertyOwner | None, owner: type[DualP
Returns:
The result of the getter.
"""
return self.getter(obj or owner)
val = self.getter(obj or owner)
return cast(DualPropertyType, val)


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

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

0 comments on commit 2c85966

Please sign in to comment.