Skip to content

Commit 473ba26

Browse files
authored
chore: more shifts towards expect_ (microsoft#432)
1 parent 52d2168 commit 473ba26

19 files changed

+276
-792
lines changed

playwright/_impl/_async_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(self, future: asyncio.Future) -> None:
3131
async def value(self) -> T:
3232
return mapping.from_maybe_impl(await self._future)
3333

34+
def is_done(self) -> bool:
35+
return self._future.done()
36+
3437

3538
class AsyncEventContextManager(Generic[T]):
3639
def __init__(self, future: asyncio.Future) -> None:

playwright/_impl/_browser_context.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ async def wait_for_event(
247247
) -> Any:
248248
async with self.expect_event(event, predicate, timeout) as event_info:
249249
pass
250-
return await event_info.value
250+
return await event_info
251251

252252
def expect_page(
253253
self,

playwright/_impl/_event_context_manager.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,16 @@
1818
T = TypeVar("T")
1919

2020

21-
class EventInfoImpl(Generic[T]):
22-
def __init__(self, future: asyncio.Future) -> None:
23-
self._future = future
24-
25-
@property
26-
async def value(self) -> T:
27-
return await self._future
28-
29-
3021
class EventContextManagerImpl(Generic[T]):
3122
def __init__(self, future: asyncio.Future) -> None:
32-
self._event: EventInfoImpl = EventInfoImpl(future)
23+
self._future: asyncio.Future = future
3324

3425
@property
3526
def future(self) -> asyncio.Future:
36-
return self._event._future
27+
return self._future
3728

38-
async def __aenter__(self) -> EventInfoImpl[T]:
39-
return self._event
29+
async def __aenter__(self) -> asyncio.Future:
30+
return self._future
4031

4132
async def __aexit__(self, *args: Any) -> None:
42-
await self._event.value
33+
await self._future

playwright/_impl/_frame.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -529,15 +529,3 @@ async def wait_for_function(
529529

530530
async def title(self) -> str:
531531
return await self._channel.send("title")
532-
533-
async def wait_for_navigation(
534-
self,
535-
url: URLMatch = None,
536-
waitUntil: DocumentLoadState = None,
537-
timeout: float = None,
538-
) -> Optional[Response]:
539-
async with self.expect_navigation(
540-
url, waitUntil, timeout=timeout
541-
) as response_info:
542-
pass
543-
return await response_info.value

playwright/_impl/_network.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ async def wait_for_event(
322322
) -> Any:
323323
async with self.expect_event(event, predicate, timeout) as event_info:
324324
pass
325-
return await event_info.value
325+
return await event_info
326326

327327
def _on_frame_sent(self, opcode: int, data: str) -> None:
328328
if opcode == 2:

playwright/_impl/_page.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -483,38 +483,12 @@ async def wait_for_load_state(
483483
) -> None:
484484
return await self._main_frame.wait_for_load_state(**locals_to_params(locals()))
485485

486-
async def wait_for_navigation(
487-
self,
488-
url: URLMatch = None,
489-
waitUntil: DocumentLoadState = None,
490-
timeout: float = None,
491-
) -> Optional[Response]:
492-
return await self._main_frame.wait_for_navigation(**locals_to_params(locals()))
493-
494-
async def wait_for_request(
495-
self,
496-
urlOrPredicate: URLMatchRequest,
497-
timeout: float = None,
498-
) -> Request:
499-
async with self.expect_request(urlOrPredicate, timeout) as request_info:
500-
pass
501-
return await request_info.value
502-
503-
async def wait_for_response(
504-
self,
505-
urlOrPredicate: URLMatchResponse,
506-
timeout: float = None,
507-
) -> Response:
508-
async with self.expect_response(urlOrPredicate, timeout) as request_info:
509-
pass
510-
return await request_info.value
511-
512486
async def wait_for_event(
513487
self, event: str, predicate: Callable = None, timeout: float = None
514488
) -> Any:
515489
async with self.expect_event(event, predicate, timeout) as event_info:
516490
pass
517-
return await event_info.value
491+
return await event_info
518492

519493
async def go_back(
520494
self,
@@ -851,7 +825,7 @@ def expect_navigation(
851825
url: URLMatch = None,
852826
wait_until: DocumentLoadState = None,
853827
timeout: float = None,
854-
) -> EventContextManagerImpl:
828+
) -> EventContextManagerImpl[Response]:
855829
return self.main_frame.expect_navigation(url, wait_until, timeout)
856830

857831
def expect_popup(

playwright/_impl/_sync_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def value(self) -> T:
5252
raise self._exception
5353
return cast(T, self._value)
5454

55+
def is_done(self) -> bool:
56+
return self._future.done()
57+
5558

5659
class EventContextManager(Generic[T]):
5760
def __init__(self, sync_base: "SyncBase", future: asyncio.Future) -> None:

0 commit comments

Comments
 (0)