Skip to content

Commit 5a4779e

Browse files
authored
fix: inherit expect context managers from contextlib (microsoft#2370)
1 parent 09f529a commit 5a4779e

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

playwright/_impl/_async_base.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
from contextlib import AbstractAsyncContextManager
1617
from types import TracebackType
17-
from typing import Any, Callable, Generic, Type, TypeVar
18+
from typing import Any, Callable, Generic, Optional, Type, TypeVar
1819

1920
from playwright._impl._impl_to_api_mapping import ImplToApiMapping, ImplWrapper
2021

@@ -40,7 +41,7 @@ def is_done(self) -> bool:
4041
return self._future.done()
4142

4243

43-
class AsyncEventContextManager(Generic[T]):
44+
class AsyncEventContextManager(Generic[T], AbstractAsyncContextManager):
4445
def __init__(self, future: "asyncio.Future[T]") -> None:
4546
self._event = AsyncEventInfo[T](future)
4647

@@ -49,9 +50,9 @@ async def __aenter__(self) -> AsyncEventInfo[T]:
4950

5051
async def __aexit__(
5152
self,
52-
exc_type: Type[BaseException],
53-
exc_val: BaseException,
54-
exc_tb: TracebackType,
53+
exc_type: Optional[Type[BaseException]],
54+
exc_val: Optional[BaseException],
55+
exc_tb: Optional[TracebackType],
5556
) -> None:
5657
if exc_val:
5758
self._event._cancel()

playwright/_impl/_sync_base.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
import asyncio
1616
import inspect
1717
import traceback
18+
from contextlib import AbstractContextManager
1819
from types import TracebackType
1920
from typing import (
2021
Any,
2122
Callable,
2223
Coroutine,
2324
Generator,
2425
Generic,
26+
Optional,
2527
Type,
2628
TypeVar,
2729
Union,
@@ -64,7 +66,7 @@ def is_done(self) -> bool:
6466
return self._future.done()
6567

6668

67-
class EventContextManager(Generic[T]):
69+
class EventContextManager(Generic[T], AbstractContextManager):
6870
def __init__(self, sync_base: "SyncBase", future: "asyncio.Future[T]") -> None:
6971
self._event = EventInfo[T](sync_base, future)
7072

@@ -73,9 +75,9 @@ def __enter__(self) -> EventInfo[T]:
7375

7476
def __exit__(
7577
self,
76-
exc_type: Type[BaseException],
77-
exc_val: BaseException,
78-
exc_tb: TracebackType,
78+
exc_type: Optional[Type[BaseException]],
79+
exc_val: Optional[BaseException],
80+
exc_tb: Optional[TracebackType],
7981
) -> None:
8082
if exc_val:
8183
self._event._cancel()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy