Skip to content

Commit 11474c5

Browse files
committed
more
1 parent 96b0ffc commit 11474c5

8 files changed

Lines changed: 97 additions & 61 deletions

File tree

playwright/_impl/_disposable.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ async def dispose(self) -> None:
3434
if not is_target_closed_error(e):
3535
raise e
3636

37+
async def close(self) -> None:
38+
await self.dispose()
39+
3740
def __repr__(self) -> str:
3841
return "<Disposable>"
3942

@@ -45,5 +48,8 @@ def __init__(self, dispose_fn: Callable[[], Awaitable[None]]) -> None:
4548
async def dispose(self) -> None:
4649
await self._dispose_fn()
4750

51+
async def close(self) -> None:
52+
await self.dispose()
53+
4854
def __repr__(self) -> str:
4955
return "<Disposable>"

playwright/async_api/_generated.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
from playwright._impl._debugger import Debugger as DebuggerImpl
6464
from playwright._impl._dialog import Dialog as DialogImpl
6565
from playwright._impl._disposable import Disposable as DisposableImpl
66-
from playwright._impl._disposable import DisposableStub
6766
from playwright._impl._download import Download as DownloadImpl
6867
from playwright._impl._element_handle import ElementHandle as ElementHandleImpl
6968
from playwright._impl._errors import Error
@@ -8886,7 +8885,7 @@ async def add_style_tag(
88868885

88878886
async def expose_function(
88888887
self, name: str, callback: typing.Callable
8889-
) -> "Disposable":
8888+
) -> "AsyncContextManager":
88908889
"""Page.expose_function
88918890

88928891
The method adds a function called `name` on the `window` object of every frame in the page. When called, the
@@ -8943,7 +8942,7 @@ async def main():
89438942

89448943
Returns
89458944
-------
8946-
Disposable
8945+
AsyncContextManager
89478946
"""
89488947

89498948
return mapping.from_impl(
@@ -8958,7 +8957,7 @@ async def expose_binding(
89588957
callback: typing.Callable,
89598958
*,
89608959
handle: typing.Optional[bool] = None,
8961-
) -> "Disposable":
8960+
) -> "AsyncContextManager":
89628961
"""Page.expose_binding
89638962

89648963
The method adds a function called `name` on the `window` object of every frame in this page. When called, the
@@ -9016,7 +9015,7 @@ async def main():
90169015

90179016
Returns
90189017
-------
9019-
Disposable
9018+
AsyncContextManager
90209019
"""
90219020

90229021
return mapping.from_impl(
@@ -9554,7 +9553,7 @@ async def add_init_script(
95549553
script: typing.Optional[str] = None,
95559554
*,
95569555
path: typing.Optional[typing.Union[pathlib.Path, str]] = None,
9557-
) -> "Disposable":
9556+
) -> "AsyncContextManager":
95589557
"""Page.add_init_script
95599558

95609559
Adds a script which would be evaluated in one of the following scenarios:
@@ -9587,7 +9586,7 @@ async def add_init_script(
95879586

95889587
Returns
95899588
-------
9590-
Disposable
9589+
AsyncContextManager
95919590
"""
95929591

95939592
return mapping.from_impl(
@@ -9603,7 +9602,7 @@ async def route(
96039602
],
96049603
*,
96059604
times: typing.Optional[int] = None,
9606-
) -> "DisposableStub":
9605+
) -> "AsyncContextManager":
96079606
"""Page.route
96089607

96099608
Routing provides the capability to modify network requests that are made by a page.
@@ -9674,7 +9673,7 @@ async def handle_route(route: Route):
96749673

96759674
Returns
96769675
-------
9677-
DisposableStub
9676+
AsyncContextManager
96789677
"""
96799678

96809679
return mapping.from_impl(
@@ -13328,7 +13327,7 @@ async def add_init_script(
1332813327
script: typing.Optional[str] = None,
1332913328
*,
1333013329
path: typing.Optional[typing.Union[pathlib.Path, str]] = None,
13331-
) -> "Disposable":
13330+
) -> "AsyncContextManager":
1333213331
"""BrowserContext.add_init_script
1333313332

1333413333
Adds a script which would be evaluated in one of the following scenarios:
@@ -13361,7 +13360,7 @@ async def add_init_script(
1336113360

1336213361
Returns
1336313362
-------
13364-
Disposable
13363+
AsyncContextManager
1336513364
"""
1336613365

1336713366
return mapping.from_impl(
@@ -13374,7 +13373,7 @@ async def expose_binding(
1337413373
callback: typing.Callable,
1337513374
*,
1337613375
handle: typing.Optional[bool] = None,
13377-
) -> "Disposable":
13376+
) -> "AsyncContextManager":
1337813377
"""BrowserContext.expose_binding
1337913378

1338013379
The method adds a function called `name` on the `window` object of every frame in every page in the context. When
@@ -13430,7 +13429,7 @@ async def main():
1343013429

1343113430
Returns
1343213431
-------
13433-
Disposable
13432+
AsyncContextManager
1343413433
"""
1343513434

1343613435
return mapping.from_impl(
@@ -13441,7 +13440,7 @@ async def main():
1344113440

1344213441
async def expose_function(
1344313442
self, name: str, callback: typing.Callable
13444-
) -> "Disposable":
13443+
) -> "AsyncContextManager":
1344513444
"""BrowserContext.expose_function
1344613445

1344713446
The method adds a function called `name` on the `window` object of every frame in every page in the context. When
@@ -13497,7 +13496,7 @@ async def main():
1349713496

1349813497
Returns
1349913498
-------
13500-
Disposable
13499+
AsyncContextManager
1350113500
"""
1350213501

1350313502
return mapping.from_impl(
@@ -13515,7 +13514,7 @@ async def route(
1351513514
],
1351613515
*,
1351713516
times: typing.Optional[int] = None,
13518-
) -> "DisposableStub":
13517+
) -> "AsyncContextManager":
1351913518
"""BrowserContext.route
1352013519

1352113520
Routing provides the capability to modify network requests that are made by any page in the browser context. Once
@@ -13580,7 +13579,7 @@ async def handle_route(route: Route):
1358013579

1358113580
Returns
1358213581
-------
13583-
DisposableStub
13582+
AsyncContextManager
1358413583
"""
1358513584

1358613585
return mapping.from_impl(
@@ -15716,7 +15715,7 @@ async def stop(
1571615715

1571715716
async def group(
1571815717
self, name: str, *, location: typing.Optional[TracingGroupLocation] = None
15719-
) -> "DisposableStub":
15718+
) -> "AsyncContextManager":
1572015719
"""Tracing.group
1572115720

1572215721
**NOTE** Use `test.step` instead when available.
@@ -15745,7 +15744,7 @@ async def group(
1574515744

1574615745
Returns
1574715746
-------
15748-
DisposableStub
15747+
AsyncContextManager
1574915748
"""
1575015749

1575115750
return mapping.from_impl(
@@ -21602,7 +21601,7 @@ async def start(
2160221601
on_frame: typing.Optional[
2160321602
typing.Callable[[OnFrame], typing.Awaitable[typing.Any]]
2160421603
] = None,
21605-
) -> "DisposableStub":
21604+
) -> "AsyncContextManager":
2160621605
"""Screencast.start
2160721606

2160821607
Starts the screencast. When `path` is provided, it saves video recording to the specified file. When `onFrame` is
@@ -21621,7 +21620,7 @@ async def start(
2162121620

2162221621
Returns
2162321622
-------
21624-
DisposableStub
21623+
AsyncContextManager
2162521624
"""
2162621625

2162721626
return mapping.from_impl(
@@ -21649,7 +21648,7 @@ async def show_actions(
2164921648
]
2165021649
] = None,
2165121650
font_size: typing.Optional[int] = None,
21652-
) -> "DisposableStub":
21651+
) -> "AsyncContextManager":
2165321652
"""Screencast.show_actions
2165421653

2165521654
Enables visual annotations on interacted elements. Returns a disposable that stops showing actions when disposed.
@@ -21665,7 +21664,7 @@ async def show_actions(
2166521664

2166621665
Returns
2166721666
-------
21668-
DisposableStub
21667+
AsyncContextManager
2166921668
"""
2167021669

2167121670
return mapping.from_impl(
@@ -21684,7 +21683,7 @@ async def hide_actions(self) -> None:
2168421683

2168521684
async def show_overlay(
2168621685
self, html: str, *, duration: typing.Optional[float] = None
21687-
) -> "DisposableStub":
21686+
) -> "AsyncContextManager":
2168821687
"""Screencast.show_overlay
2168921688

2169021689
Adds an overlay with the given HTML content. The overlay is displayed on top of the page until removed. Returns a
@@ -21700,7 +21699,7 @@ async def show_overlay(
2170021699

2170121700
Returns
2170221701
-------
21703-
DisposableStub
21702+
AsyncContextManager
2170421703
"""
2170521704

2170621705
return mapping.from_impl(
@@ -21755,7 +21754,7 @@ async def hide_overlays(self) -> None:
2175521754
mapping.register(ScreencastImpl, Screencast)
2175621755

2175721756

21758-
class Disposable(AsyncBase):
21757+
class Disposable(AsyncContextManager):
2175921758

2176021759
async def dispose(self) -> None:
2176121760
"""Disposable.dispose
@@ -21766,5 +21765,9 @@ async def dispose(self) -> None:
2176621765

2176721766
return mapping.from_maybe_impl(await self._impl_obj.dispose())
2176821767

21768+
async def close(self) -> None:
21769+
21770+
return mapping.from_maybe_impl(await self._impl_obj.close())
21771+
2176921772

2177021773
mapping.register(DisposableImpl, Disposable)

0 commit comments

Comments
 (0)