Skip to content

Commit 93c60af

Browse files
authored
chore: unflake test_expect_file_chooser tests (#1183)
1 parent b6cda7d commit 93c60af

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

playwright/_impl/_sync_base.py

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,7 @@
1515
import asyncio
1616
import traceback
1717
from types import TracebackType
18-
from typing import (
19-
Any,
20-
Awaitable,
21-
Callable,
22-
Dict,
23-
Generic,
24-
List,
25-
Optional,
26-
Type,
27-
TypeVar,
28-
cast,
29-
)
18+
from typing import Any, Awaitable, Callable, Dict, Generic, List, Type, TypeVar, cast
3019

3120
import greenlet
3221

@@ -42,29 +31,19 @@
4231
class EventInfo(Generic[T]):
4332
def __init__(self, sync_base: "SyncBase", future: "asyncio.Future[T]") -> None:
4433
self._sync_base = sync_base
45-
self._value: Optional[T] = None
46-
self._exception: Optional[Exception] = None
4734
self._future = future
4835
g_self = greenlet.getcurrent()
49-
50-
def done_callback(task: "asyncio.Future[T]") -> None:
51-
try:
52-
self._value = mapping.from_maybe_impl(self._future.result())
53-
except Exception as e:
54-
self._exception = e
55-
finally:
56-
g_self.switch()
57-
58-
self._future.add_done_callback(done_callback)
36+
self._future.add_done_callback(lambda _: g_self.switch())
5937

6038
@property
6139
def value(self) -> T:
6240
while not self._future.done():
6341
self._sync_base._dispatcher_fiber.switch()
6442
asyncio._set_running_loop(self._sync_base._loop)
65-
if self._exception:
66-
raise self._exception
67-
return cast(T, self._value)
43+
exception = self._future.exception()
44+
if exception:
45+
raise exception
46+
return cast(T, mapping.from_maybe_impl(self._future.result()))
6847

6948
def is_done(self) -> bool:
7049
return self._future.done()

0 commit comments

Comments
 (0)