Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ dev = [
"pytest-timeout~=2.3.0",
"pytest-xdist~=3.6.0",
"respx~=0.22.0",
"ruff~=0.9.0",
"ruff~=0.10.0",
"setuptools~=76.0.0", # setuptools are used by pytest but not explicitly required
]

Expand Down
8 changes: 4 additions & 4 deletions src/apify/_actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ async def __aexit__(
await self.exit()

def __repr__(self) -> str:
if self is cast(Proxy, Actor).__wrapped__:
if self is cast('Proxy', Actor).__wrapped__:
return '<apify.Actor>'

return super().__repr__()
Expand Down Expand Up @@ -222,7 +222,7 @@ async def init(self) -> None:
self.log.warning('Repeated Actor initialization detected - this is non-standard usage, proceed with care')

# Make sure that the currently initialized instance is also available through the global `Actor` proxy
cast(Proxy, Actor).__wrapped__ = self
cast('Proxy', Actor).__wrapped__ = self

self._is_exiting = False
self._was_final_persist_state_emitted = False
Expand Down Expand Up @@ -674,7 +674,7 @@ def get_env(self) -> dict:
elif isinstance(field.validation_alias, str):
aliases = [field.validation_alias]
elif isinstance(field.validation_alias, AliasChoices):
aliases = cast(list[str], field.validation_alias.choices)
aliases = cast('list[str]', field.validation_alias.choices)
else:
aliases = [field_name]

Expand Down Expand Up @@ -1158,5 +1158,5 @@ def _get_default_exit_process(self) -> bool:
return True


Actor = cast(_ActorType, Proxy(_ActorType))
Actor = cast('_ActorType', Proxy(_ActorType))
"""The entry point of the SDK, through which all the Actor operations should be done."""
2 changes: 1 addition & 1 deletion src/apify/scrapy/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def to_scrapy_request(apify_request: ApifyRequest, spider: Spider) -> ScrapyRequ
Returns:
The converted Scrapy request.
"""
if not isinstance(cast(Any, apify_request), ApifyRequest):
if not isinstance(cast('Any', apify_request), ApifyRequest):
raise TypeError('apify_request must be a crawlee.ScrapyRequest instance')

logger.debug(f'to_scrapy_request was called (apify_request={apify_request})...')
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/actor/test_actor_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
import json
import sys
from datetime import datetime, timezone
from typing import Any, Callable, cast
from typing import TYPE_CHECKING, Any, Callable, cast
from unittest.mock import AsyncMock, Mock

import pytest
import websockets.asyncio.server
from lazy_object_proxy import Proxy

from apify_shared.consts import ActorEnvVars, ApifyEnvVars
from crawlee.events._types import Event, EventPersistStateData
Expand All @@ -19,12 +18,15 @@
from apify import Actor
from apify._actor import _ActorType

if TYPE_CHECKING:
from lazy_object_proxy import Proxy


async def test_actor_properly_init_with_async() -> None:
async with Actor:
assert cast(Proxy, apify._actor.Actor).__wrapped__ is not None
assert cast(Proxy, apify._actor.Actor).__wrapped__._is_initialized
assert not cast(Proxy, apify._actor.Actor).__wrapped__._is_initialized
assert cast('Proxy', apify._actor.Actor).__wrapped__ is not None
assert cast('Proxy', apify._actor.Actor).__wrapped__._is_initialized
assert not cast('Proxy', apify._actor.Actor).__wrapped__._is_initialized


async def test_actor_init() -> None:
Expand Down
44 changes: 22 additions & 22 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.