44import logging
55import warnings
66from datetime import timedelta
7- from typing import TYPE_CHECKING , Any , Generic , Literal
7+ from functools import partial
8+ from typing import TYPE_CHECKING , Any , Generic , Literal , cast
89
910import playwright .async_api
1011from more_itertools import partition
@@ -250,7 +251,7 @@ async def _open_page(
250251 log = context .log ,
251252 register_deferred_cleanup = context .register_deferred_cleanup ,
252253 page = crawlee_page .page ,
253- block_requests = self . _make_block_requests ( crawlee_page .page ),
254+ block_requests = cast ( 'BlockRequestsFunction' , partial ( block_requests , page = crawlee_page .page ) ),
254255 goto_options = GotoOptions (** self ._goto_options ),
255256 )
256257
@@ -534,7 +535,7 @@ async def _create_crawling_context(
534535 infinite_scroll = lambda : infinite_scroll (context .page ),
535536 extract_links = extract_links ,
536537 enqueue_links = self ._create_enqueue_links_function (context , extract_links ),
537- block_requests = self . _make_block_requests ( context .page ),
538+ block_requests = cast ( 'BlockRequestsFunction' , partial ( block_requests , page = context .page ) ),
538539 )
539540
540541 if context .session :
@@ -557,18 +558,6 @@ def post_navigation_hook(self, hook: Callable[[PlaywrightPostNavCrawlingContext]
557558 """
558559 self ._post_navigation_hooks .append (hook )
559560
560- @staticmethod
561- def _make_block_requests (page : Page ) -> BlockRequestsFunction :
562- """Build a `BlockRequestsFunction` bound to the given page."""
563-
564- async def _bound_block_requests (
565- url_patterns : list [str ] | None = None ,
566- extra_url_patterns : list [str ] | None = None ,
567- ) -> None :
568- await block_requests (page , url_patterns = url_patterns , extra_url_patterns = extra_url_patterns )
569-
570- return _bound_block_requests
571-
572561 async def _get_cookies (self , page : Page ) -> list [PlaywrightCookieParam ]:
573562 """Get the cookies from the page."""
574563 cookies = await page .context .cookies ()
0 commit comments