From 447892528c56e6d0bbdd09e4ac31a735a73f79d3 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Fri, 3 Feb 2023 14:50:35 +0100 Subject: [PATCH] chore: update pre-commit (#1750) --- .pre-commit-config.yaml | 6 +++--- playwright/_impl/_browser.py | 1 - playwright/_impl/_browser_context.py | 1 - playwright/_impl/_network.py | 1 - playwright/_impl/_page.py | 1 - playwright/async_api/_generated.py | 25 ++++++++++++++++--------- playwright/sync_api/_context_manager.py | 7 +++++-- playwright/sync_api/_generated.py | 25 ++++++++++++++++--------- scripts/generate_api.py | 1 + tests/async/test_har.py | 1 - tests/sync/test_har.py | 1 - 11 files changed, 41 insertions(+), 29 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6a46b88cc..f1d634094 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,7 +2,7 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -15,7 +15,7 @@ repos: - id: check-executables-have-shebangs - id: check-merge-conflict - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 23.1.0 hooks: - id: black - repo: https://github.com/pre-commit/mirrors-mypy @@ -28,7 +28,7 @@ repos: hooks: - id: flake8 - repo: https://github.com/pycqa/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort - repo: local diff --git a/playwright/_impl/_browser.py b/playwright/_impl/_browser.py index a59f96cc0..e9d0dde1b 100644 --- a/playwright/_impl/_browser.py +++ b/playwright/_impl/_browser.py @@ -48,7 +48,6 @@ class Browser(ChannelOwner): - Events = SimpleNamespace( Disconnected="disconnected", ) diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py index 07c9ae79e..2cad9af7b 100644 --- a/playwright/_impl/_browser_context.py +++ b/playwright/_impl/_browser_context.py @@ -73,7 +73,6 @@ class BrowserContext(ChannelOwner): - Events = SimpleNamespace( BackgroundPage="backgroundpage", Close="close", diff --git a/playwright/_impl/_network.py b/playwright/_impl/_network.py index bd8aa4221..894e802c7 100644 --- a/playwright/_impl/_network.py +++ b/playwright/_impl/_network.py @@ -545,7 +545,6 @@ def frame(self) -> "Frame": class WebSocket(ChannelOwner): - Events = SimpleNamespace( Close="close", FrameReceived="framereceived", diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index 1b930d950..a40fe4d10 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -102,7 +102,6 @@ class Page(ChannelOwner): - Events = SimpleNamespace( Close="close", Crash="crash", diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index 497d481d5..0595f5751 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -7331,7 +7331,8 @@ def on( page.on(\"dialog\", lambda dialog: dialog.accept()) ``` - **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed.""" + **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed. + """ @typing.overload def on( @@ -7341,7 +7342,8 @@ def on( ) -> None: """ Emitted when the JavaScript - [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.""" + [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched. + """ @typing.overload def on( @@ -7403,7 +7405,8 @@ def on( f: typing.Callable[["Page"], "typing.Union[typing.Awaitable[None], None]"], ) -> None: """ - Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.""" + Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched. + """ @typing.overload def on( @@ -7628,7 +7631,8 @@ def once( page.on(\"dialog\", lambda dialog: dialog.accept()) ``` - **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed.""" + **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed. + """ @typing.overload def once( @@ -7638,7 +7642,8 @@ def once( ) -> None: """ Emitted when the JavaScript - [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.""" + [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched. + """ @typing.overload def once( @@ -7700,7 +7705,8 @@ def once( f: typing.Callable[["Page"], "typing.Union[typing.Awaitable[None], None]"], ) -> None: """ - Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.""" + Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched. + """ @typing.overload def once( @@ -12421,7 +12427,8 @@ def on( Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To only listen for requests from a particular page, use `page.on('request')`. - In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`.""" + In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`. + """ @typing.overload def on( @@ -12552,7 +12559,8 @@ def once( Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To only listen for requests from a particular page, use `page.on('request')`. - In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`.""" + In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`. + """ @typing.overload def once( @@ -14847,7 +14855,6 @@ def request(self) -> "APIRequest": return mapping.from_impl(self._impl_obj.request) def __getitem__(self, value: str) -> "BrowserType": - return mapping.from_impl(self._impl_obj.__getitem__(value=value)) def stop(self) -> None: diff --git a/playwright/sync_api/_context_manager.py b/playwright/sync_api/_context_manager.py index 5cae1ea1d..3b5c6d8b4 100644 --- a/playwright/sync_api/_context_manager.py +++ b/playwright/sync_api/_context_manager.py @@ -14,7 +14,7 @@ import asyncio import sys -from typing import Any, Optional, cast +from typing import TYPE_CHECKING, Any, Optional, cast from greenlet import greenlet @@ -26,13 +26,16 @@ from playwright._impl._transport import PipeTransport from playwright.sync_api._generated import Playwright as SyncPlaywright +if TYPE_CHECKING: + from asyncio.unix_events import AbstractChildWatcher + class PlaywrightContextManager: def __init__(self) -> None: self._playwright: SyncPlaywright self._loop: asyncio.AbstractEventLoop self._own_loop = False - self._watcher: Optional[asyncio.AbstractChildWatcher] = None + self._watcher: Optional[AbstractChildWatcher] = None def __enter__(self) -> SyncPlaywright: try: diff --git a/playwright/sync_api/_generated.py b/playwright/sync_api/_generated.py index 995985d55..5aa50a668 100644 --- a/playwright/sync_api/_generated.py +++ b/playwright/sync_api/_generated.py @@ -7433,7 +7433,8 @@ def on( page.on(\"dialog\", lambda dialog: dialog.accept()) ``` - **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed.""" + **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed. + """ @typing.overload def on( @@ -7441,7 +7442,8 @@ def on( ) -> None: """ Emitted when the JavaScript - [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.""" + [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched. + """ @typing.overload def on( @@ -7487,7 +7489,8 @@ def on( @typing.overload def on(self, event: Literal["load"], f: typing.Callable[["Page"], "None"]) -> None: """ - Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.""" + Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched. + """ @typing.overload def on( @@ -7680,7 +7683,8 @@ def once( page.on(\"dialog\", lambda dialog: dialog.accept()) ``` - **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed.""" + **NOTE** When no `page.on('dialog')` listeners are present, all dialogs are automatically dismissed. + """ @typing.overload def once( @@ -7688,7 +7692,8 @@ def once( ) -> None: """ Emitted when the JavaScript - [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched.""" + [`DOMContentLoaded`](https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded) event is dispatched. + """ @typing.overload def once( @@ -7736,7 +7741,8 @@ def once( self, event: Literal["load"], f: typing.Callable[["Page"], "None"] ) -> None: """ - Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched.""" + Emitted when the JavaScript [`load`](https://developer.mozilla.org/en-US/docs/Web/Events/load) event is dispatched. + """ @typing.overload def once( @@ -12515,7 +12521,8 @@ def on( Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To only listen for requests from a particular page, use `page.on('request')`. - In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`.""" + In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`. + """ @typing.overload def on( @@ -12624,7 +12631,8 @@ def once( Emitted when a request is issued from any pages created through this context. The [request] object is read-only. To only listen for requests from a particular page, use `page.on('request')`. - In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`.""" + In order to intercept and mutate requests, see `browser_context.route()` or `page.route()`. + """ @typing.overload def once( @@ -14931,7 +14939,6 @@ def request(self) -> "APIRequest": return mapping.from_impl(self._impl_obj.request) def __getitem__(self, value: str) -> "BrowserType": - return mapping.from_impl(self._impl_obj.__getitem__(value=value)) def stop(self) -> None: diff --git a/scripts/generate_api.py b/scripts/generate_api.py index 9b2319158..a84327eac 100644 --- a/scripts/generate_api.py +++ b/scripts/generate_api.py @@ -289,6 +289,7 @@ def return_value(value: Any) -> List[str]: api_globals = globals() assert Serializable + # Python 3.11+ does not treat default args with None as Optional anymore, this wrapper will still wrap them. # https://github.com/python/cpython/issues/90353 def get_type_hints(func: Any, globalns: Any) -> Dict[str, Any]: diff --git a/tests/async/test_har.py b/tests/async/test_har.py index cd1c871a6..d2df88a28 100644 --- a/tests/async/test_har.py +++ b/tests/async/test_har.py @@ -486,7 +486,6 @@ async def test_should_fulfill_from_har_with_content_in_a_file( async def test_should_round_trip_har_zip( browser: Browser, server: Server, assetdir: Path, tmpdir: Path ) -> None: - har_path = tmpdir / "har.zip" context_1 = await browser.new_context( record_har_mode="minimal", record_har_path=har_path diff --git a/tests/sync/test_har.py b/tests/sync/test_har.py index 81452c9de..33441826f 100644 --- a/tests/sync/test_har.py +++ b/tests/sync/test_har.py @@ -425,7 +425,6 @@ def test_should_fulfill_from_har_with_content_in_a_file( def test_should_round_trip_har_zip( browser: Browser, server: Server, assetdir: Path, tmpdir: Path ) -> None: - har_path = tmpdir / "har.zip" context_1 = browser.new_context(record_har_mode="minimal", record_har_path=har_path) page_1 = context_1.new_page()