From 42afbd7adbe880fc1e04b8bf16ccb978ab0f342a Mon Sep 17 00:00:00 2001 From: danphenderson Date: Thu, 15 Feb 2024 16:34:34 -0800 Subject: [PATCH 1/9] fix(wip): incorrect type hints for optional params/attributes Commit was automated using this powerful one-liner: `find . -type f -name "*.py" -print0 | xargs -0 perl -i -pe \ 's/([a-zA-Z_]+): (?!(Optional\[|Any\]))([a-zA-Z_]+) = None/\1: Optional[\3] = None/g'` Which modifies variable annotations initialized with None to use Optional[Type], except when the type is already annotated as Optional[Type] or Any After executing the command, I manually updated modules that didn't already import Optional. issue: 2303 --- playwright/_impl/_accessibility.py | 4 +- playwright/_impl/_assertions.py | 136 ++++---- playwright/_impl/_browser.py | 118 +++---- playwright/_impl/_browser_context.py | 35 +- playwright/_impl/_browser_type.py | 106 +++--- playwright/_impl/_cdp_session.py | 4 +- playwright/_impl/_connection.py | 10 +- playwright/_impl/_dialog.py | 2 +- playwright/_impl/_element_handle.py | 142 ++++---- playwright/_impl/_errors.py | 2 +- playwright/_impl/_fetch.py | 152 ++++----- playwright/_impl/_file_chooser.py | 6 +- playwright/_impl/_frame.py | 307 +++++++++-------- playwright/_impl/_helper.py | 2 +- playwright/_impl/_impl_to_api_mapping.py | 2 +- playwright/_impl/_input.py | 26 +- playwright/_impl/_js_handle.py | 8 +- playwright/_impl/_locator.py | 296 +++++++++-------- playwright/_impl/_network.py | 39 ++- playwright/_impl/_page.py | 405 +++++++++++++---------- playwright/_impl/_selectors.py | 6 +- playwright/_impl/_str_utils.py | 8 +- playwright/_impl/_tracing.py | 14 +- playwright/_impl/_waiter.py | 14 +- 24 files changed, 991 insertions(+), 853 deletions(-) diff --git a/playwright/_impl/_accessibility.py b/playwright/_impl/_accessibility.py index 010b4e8c5..d191033d2 100644 --- a/playwright/_impl/_accessibility.py +++ b/playwright/_impl/_accessibility.py @@ -60,7 +60,9 @@ def __init__(self, channel: Channel) -> None: self._dispatcher_fiber = channel._connection._dispatcher_fiber async def snapshot( - self, interestingOnly: bool = None, root: ElementHandle = None + self, + interestingOnly: Optional[bool] = None, + root: Optional[ElementHandle] = None, ) -> Optional[Dict]: params = locals_to_params(locals()) if root: diff --git a/playwright/_impl/_assertions.py b/playwright/_impl/_assertions.py index 2c895e527..ee0b6cbd9 100644 --- a/playwright/_impl/_assertions.py +++ b/playwright/_impl/_assertions.py @@ -30,7 +30,7 @@ class AssertionsBase: def __init__( self, locator: Locator, - timeout: float = None, + timeout: Optional[float] = None, is_not: bool = False, message: Optional[str] = None, ) -> None: @@ -76,7 +76,7 @@ class PageAssertions(AssertionsBase): def __init__( self, page: Page, - timeout: float = None, + timeout: Optional[float] = None, is_not: bool = False, message: Optional[str] = None, ) -> None: @@ -90,7 +90,7 @@ def _not(self) -> "PageAssertions": ) async def to_have_title( - self, titleOrRegExp: Union[Pattern[str], str], timeout: float = None + self, titleOrRegExp: Union[Pattern[str], str], timeout: Optional[float] = None ) -> None: expected_values = to_expected_text_values( [titleOrRegExp], normalize_white_space=True @@ -104,13 +104,13 @@ async def to_have_title( ) async def not_to_have_title( - self, titleOrRegExp: Union[Pattern[str], str], timeout: float = None + self, titleOrRegExp: Union[Pattern[str], str], timeout: Optional[float] = None ) -> None: __tracebackhide__ = True await self._not.to_have_title(titleOrRegExp, timeout) async def to_have_url( - self, urlOrRegExp: Union[str, Pattern[str]], timeout: float = None + self, urlOrRegExp: Union[str, Pattern[str]], timeout: Optional[float] = None ) -> None: __tracebackhide__ = True base_url = self._actual_page.context._options.get("baseURL") @@ -125,7 +125,7 @@ async def to_have_url( ) async def not_to_have_url( - self, urlOrRegExp: Union[Pattern[str], str], timeout: float = None + self, urlOrRegExp: Union[Pattern[str], str], timeout: Optional[float] = None ) -> None: __tracebackhide__ = True await self._not.to_have_url(urlOrRegExp, timeout) @@ -135,7 +135,7 @@ class LocatorAssertions(AssertionsBase): def __init__( self, locator: Locator, - timeout: float = None, + timeout: Optional[float] = None, is_not: bool = False, message: Optional[str] = None, ) -> None: @@ -157,9 +157,9 @@ async def to_contain_text( Pattern[str], str, ], - useInnerText: bool = None, - timeout: float = None, - ignoreCase: bool = None, + useInnerText: Optional[bool] = None, + timeout: Optional[float] = None, + ignoreCase: Optional[bool] = None, ) -> None: __tracebackhide__ = True if isinstance(expected, collections.abc.Sequence) and not isinstance( @@ -208,9 +208,9 @@ async def not_to_contain_text( Pattern[str], str, ], - useInnerText: bool = None, - timeout: float = None, - ignoreCase: bool = None, + useInnerText: Optional[bool] = None, + timeout: Optional[float] = None, + ignoreCase: Optional[bool] = None, ) -> None: __tracebackhide__ = True await self._not.to_contain_text(expected, useInnerText, timeout, ignoreCase) @@ -219,8 +219,8 @@ async def to_have_attribute( self, name: str, value: Union[str, Pattern[str]], - ignoreCase: bool = None, - timeout: float = None, + ignoreCase: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True expected_text = to_expected_text_values([value], ignoreCase=ignoreCase) @@ -237,8 +237,8 @@ async def not_to_have_attribute( self, name: str, value: Union[str, Pattern[str]], - ignoreCase: bool = None, - timeout: float = None, + ignoreCase: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_attribute( @@ -254,7 +254,7 @@ async def to_have_class( Pattern[str], str, ], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True if isinstance(expected, collections.abc.Sequence) and not isinstance( @@ -285,7 +285,7 @@ async def not_to_have_class( Pattern[str], str, ], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_class(expected, timeout) @@ -293,7 +293,7 @@ async def not_to_have_class( async def to_have_count( self, count: int, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -306,7 +306,7 @@ async def to_have_count( async def not_to_have_count( self, count: int, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_count(count, timeout) @@ -315,7 +315,7 @@ async def to_have_css( self, name: str, value: Union[str, Pattern[str]], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True expected_text = to_expected_text_values([value]) @@ -332,7 +332,7 @@ async def not_to_have_css( self, name: str, value: Union[str, Pattern[str]], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_css(name, value, timeout) @@ -340,7 +340,7 @@ async def not_to_have_css( async def to_have_id( self, id: Union[str, Pattern[str]], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True expected_text = to_expected_text_values([id]) @@ -354,7 +354,7 @@ async def to_have_id( async def not_to_have_id( self, id: Union[str, Pattern[str]], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_id(id, timeout) @@ -363,7 +363,7 @@ async def to_have_js_property( self, name: str, value: Any, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -379,7 +379,7 @@ async def not_to_have_js_property( self, name: str, value: Any, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_js_property(name, value, timeout) @@ -387,7 +387,7 @@ async def not_to_have_js_property( async def to_have_value( self, value: Union[str, Pattern[str]], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True expected_text = to_expected_text_values([value]) @@ -401,7 +401,7 @@ async def to_have_value( async def not_to_have_value( self, value: Union[str, Pattern[str]], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_value(value, timeout) @@ -411,7 +411,7 @@ async def to_have_values( values: Union[ Sequence[str], Sequence[Pattern[str]], Sequence[Union[Pattern[str], str]] ], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True expected_text = to_expected_text_values(values) @@ -427,7 +427,7 @@ async def not_to_have_values( values: Union[ Sequence[str], Sequence[Pattern[str]], Sequence[Union[Pattern[str], str]] ], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_values(values, timeout) @@ -441,9 +441,9 @@ async def to_have_text( Pattern[str], str, ], - useInnerText: bool = None, - timeout: float = None, - ignoreCase: bool = None, + useInnerText: Optional[bool] = None, + timeout: Optional[float] = None, + ignoreCase: Optional[bool] = None, ) -> None: __tracebackhide__ = True if isinstance(expected, collections.abc.Sequence) and not isinstance( @@ -488,17 +488,17 @@ async def not_to_have_text( Pattern[str], str, ], - useInnerText: bool = None, - timeout: float = None, - ignoreCase: bool = None, + useInnerText: Optional[bool] = None, + timeout: Optional[float] = None, + ignoreCase: Optional[bool] = None, ) -> None: __tracebackhide__ = True await self._not.to_have_text(expected, useInnerText, timeout, ignoreCase) async def to_be_attached( self, - attached: bool = None, - timeout: float = None, + attached: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -512,8 +512,8 @@ async def to_be_attached( async def to_be_checked( self, - timeout: float = None, - checked: bool = None, + timeout: Optional[float] = None, + checked: Optional[bool] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -527,22 +527,22 @@ async def to_be_checked( async def not_to_be_attached( self, - attached: bool = None, - timeout: float = None, + attached: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_attached(attached=attached, timeout=timeout) async def not_to_be_checked( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_checked(timeout) async def to_be_disabled( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -554,15 +554,15 @@ async def to_be_disabled( async def not_to_be_disabled( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_disabled(timeout) async def to_be_editable( self, - editable: bool = None, - timeout: float = None, + editable: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True if editable is None: @@ -576,15 +576,15 @@ async def to_be_editable( async def not_to_be_editable( self, - editable: bool = None, - timeout: float = None, + editable: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_editable(editable, timeout) async def to_be_empty( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -596,15 +596,15 @@ async def to_be_empty( async def not_to_be_empty( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_empty(timeout) async def to_be_enabled( self, - enabled: bool = None, - timeout: float = None, + enabled: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True if enabled is None: @@ -618,15 +618,15 @@ async def to_be_enabled( async def not_to_be_enabled( self, - enabled: bool = None, - timeout: float = None, + enabled: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_enabled(enabled, timeout) async def to_be_hidden( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -638,15 +638,15 @@ async def to_be_hidden( async def not_to_be_hidden( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_hidden(timeout) async def to_be_visible( self, - visible: bool = None, - timeout: float = None, + visible: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True if visible is None: @@ -660,15 +660,15 @@ async def to_be_visible( async def not_to_be_visible( self, - visible: bool = None, - timeout: float = None, + visible: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_visible(visible, timeout) async def to_be_focused( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -680,15 +680,15 @@ async def to_be_focused( async def not_to_be_focused( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._not.to_be_focused(timeout) async def to_be_in_viewport( self, - ratio: float = None, - timeout: float = None, + ratio: Optional[float] = None, + timeout: Optional[float] = None, ) -> None: __tracebackhide__ = True await self._expect_impl( @@ -699,7 +699,7 @@ async def to_be_in_viewport( ) async def not_to_be_in_viewport( - self, ratio: float = None, timeout: float = None + self, ratio: Optional[float] = None, timeout: Optional[float] = None ) -> None: __tracebackhide__ = True await self._not.to_be_in_viewport(ratio=ratio, timeout=timeout) @@ -709,7 +709,7 @@ class APIResponseAssertions: def __init__( self, response: APIResponse, - timeout: float = None, + timeout: Optional[float] = None, is_not: bool = False, message: Optional[str] = None, ) -> None: diff --git a/playwright/_impl/_browser.py b/playwright/_impl/_browser.py index 8a248f703..2fbad03fa 100644 --- a/playwright/_impl/_browser.py +++ b/playwright/_impl/_browser.py @@ -86,40 +86,40 @@ def is_connected(self) -> bool: async def new_context( self, - viewport: ViewportSize = None, - screen: ViewportSize = None, - noViewport: bool = None, - ignoreHTTPSErrors: bool = None, - javaScriptEnabled: bool = None, - bypassCSP: bool = None, - userAgent: str = None, - locale: str = None, - timezoneId: str = None, - geolocation: Geolocation = None, + viewport: Optional[ViewportSize] = None, + screen: Optional[ViewportSize] = None, + noViewport: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + javaScriptEnabled: Optional[bool] = None, + bypassCSP: Optional[bool] = None, + userAgent: Optional[str] = None, + locale: Optional[str] = None, + timezoneId: Optional[str] = None, + geolocation: Optional[Geolocation] = None, permissions: Sequence[str] = None, extraHTTPHeaders: Dict[str, str] = None, - offline: bool = None, - httpCredentials: HttpCredentials = None, - deviceScaleFactor: float = None, - isMobile: bool = None, - hasTouch: bool = None, - colorScheme: ColorScheme = None, - reducedMotion: ReducedMotion = None, - forcedColors: ForcedColors = None, - acceptDownloads: bool = None, - defaultBrowserType: str = None, - proxy: ProxySettings = None, + offline: Optional[bool] = None, + httpCredentials: Optional[HttpCredentials] = None, + deviceScaleFactor: Optional[float] = None, + isMobile: Optional[bool] = None, + hasTouch: Optional[bool] = None, + colorScheme: Optional[ColorScheme] = None, + reducedMotion: Optional[ReducedMotion] = None, + forcedColors: Optional[ForcedColors] = None, + acceptDownloads: Optional[bool] = None, + defaultBrowserType: Optional[str] = None, + proxy: Optional[ProxySettings] = None, recordHarPath: Union[Path, str] = None, - recordHarOmitContent: bool = None, + recordHarOmitContent: Optional[bool] = None, recordVideoDir: Union[Path, str] = None, - recordVideoSize: ViewportSize = None, + recordVideoSize: Optional[ViewportSize] = None, storageState: Union[StorageState, str, Path] = None, - baseURL: str = None, - strictSelectors: bool = None, - serviceWorkers: ServiceWorkersPolicy = None, + baseURL: Optional[str] = None, + strictSelectors: Optional[bool] = None, + serviceWorkers: Optional[ServiceWorkersPolicy] = None, recordHarUrlFilter: Union[Pattern[str], str] = None, - recordHarMode: HarMode = None, - recordHarContent: HarContentPolicy = None, + recordHarMode: Optional[HarMode] = None, + recordHarContent: Optional[HarContentPolicy] = None, ) -> BrowserContext: params = locals_to_params(locals()) await prepare_browser_context_params(params) @@ -131,40 +131,40 @@ async def new_context( async def new_page( self, - viewport: ViewportSize = None, - screen: ViewportSize = None, - noViewport: bool = None, - ignoreHTTPSErrors: bool = None, - javaScriptEnabled: bool = None, - bypassCSP: bool = None, - userAgent: str = None, - locale: str = None, - timezoneId: str = None, - geolocation: Geolocation = None, + viewport: Optional[ViewportSize] = None, + screen: Optional[ViewportSize] = None, + noViewport: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + javaScriptEnabled: Optional[bool] = None, + bypassCSP: Optional[bool] = None, + userAgent: Optional[str] = None, + locale: Optional[str] = None, + timezoneId: Optional[str] = None, + geolocation: Optional[Geolocation] = None, permissions: Sequence[str] = None, extraHTTPHeaders: Dict[str, str] = None, - offline: bool = None, - httpCredentials: HttpCredentials = None, - deviceScaleFactor: float = None, - isMobile: bool = None, - hasTouch: bool = None, - colorScheme: ColorScheme = None, - forcedColors: ForcedColors = None, - reducedMotion: ReducedMotion = None, - acceptDownloads: bool = None, - defaultBrowserType: str = None, - proxy: ProxySettings = None, + offline: Optional[bool] = None, + httpCredentials: Optional[HttpCredentials] = None, + deviceScaleFactor: Optional[float] = None, + isMobile: Optional[bool] = None, + hasTouch: Optional[bool] = None, + colorScheme: Optional[ColorScheme] = None, + forcedColors: Optional[ForcedColors] = None, + reducedMotion: Optional[ReducedMotion] = None, + acceptDownloads: Optional[bool] = None, + defaultBrowserType: Optional[str] = None, + proxy: Optional[ProxySettings] = None, recordHarPath: Union[Path, str] = None, - recordHarOmitContent: bool = None, + recordHarOmitContent: Optional[bool] = None, recordVideoDir: Union[Path, str] = None, - recordVideoSize: ViewportSize = None, + recordVideoSize: Optional[ViewportSize] = None, storageState: Union[StorageState, str, Path] = None, - baseURL: str = None, - strictSelectors: bool = None, - serviceWorkers: ServiceWorkersPolicy = None, + baseURL: Optional[str] = None, + strictSelectors: Optional[bool] = None, + serviceWorkers: Optional[ServiceWorkersPolicy] = None, recordHarUrlFilter: Union[Pattern[str], str] = None, - recordHarMode: HarMode = None, - recordHarContent: HarContentPolicy = None, + recordHarMode: Optional[HarMode] = None, + recordHarContent: Optional[HarContentPolicy] = None, ) -> Page: params = locals_to_params(locals()) @@ -177,7 +177,7 @@ async def inner() -> Page: return await self._connection.wrap_api_call(inner) - async def close(self, reason: str = None) -> None: + async def close(self, reason: Optional[str] = None) -> None: self._close_reason = reason try: if self._should_close_connection_on_close: @@ -197,9 +197,9 @@ async def new_browser_cdp_session(self) -> CDPSession: async def start_tracing( self, - page: Page = None, + page: Optional[Page] = None, path: Union[str, Path] = None, - screenshots: bool = None, + screenshots: Optional[bool] = None, categories: Sequence[str] = None, ) -> None: params = locals_to_params(locals()) diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py index c05b427f2..d3377e4be 100644 --- a/playwright/_impl/_browser_context.py +++ b/playwright/_impl/_browser_context.py @@ -311,14 +311,14 @@ async def clear_cookies(self) -> None: await self._channel.send("clearCookies") async def grant_permissions( - self, permissions: Sequence[str], origin: str = None + self, permissions: Sequence[str], origin: Optional[str] = None ) -> None: await self._channel.send("grantPermissions", locals_to_params(locals())) async def clear_permissions(self) -> None: await self._channel.send("clearPermissions") - async def set_geolocation(self, geolocation: Geolocation = None) -> None: + async def set_geolocation(self, geolocation: Optional[Geolocation] = None) -> None: await self._channel.send("setGeolocation", locals_to_params(locals())) async def set_extra_http_headers(self, headers: Dict[str, str]) -> None: @@ -330,7 +330,7 @@ async def set_offline(self, offline: bool) -> None: await self._channel.send("setOffline", dict(offline=offline)) async def add_init_script( - self, script: str = None, path: Union[str, Path] = None + self, script: Optional[str] = None, path: Union[str, Path] = None ) -> None: if path: script = (await async_readfile(path)).decode() @@ -339,7 +339,7 @@ async def add_init_script( await self._channel.send("addInitScript", dict(source=script)) async def expose_binding( - self, name: str, callback: Callable, handle: bool = None + self, name: str, callback: Callable, handle: Optional[bool] = None ) -> None: for page in self._pages: if name in page._bindings: @@ -357,7 +357,7 @@ async def expose_function(self, name: str, callback: Callable) -> None: await self.expose_binding(name, lambda source, *args: callback(*args)) async def route( - self, url: URLMatch, handler: RouteHandlerCallback, times: int = None + self, url: URLMatch, handler: RouteHandlerCallback, times: Optional[int] = None ) -> None: self._routes.insert( 0, @@ -410,8 +410,8 @@ async def _record_into_har( har: Union[Path, str], page: Optional[Page] = None, url: Union[Pattern[str], str] = None, - update_content: HarContentPolicy = None, - update_mode: HarMode = None, + update_content: Optional[HarContentPolicy] = None, + update_mode: Optional[HarMode] = None, ) -> None: params: Dict[str, Any] = { "options": prepare_record_har_options( @@ -435,10 +435,10 @@ async def route_from_har( self, har: Union[Path, str], url: Union[Pattern[str], str] = None, - notFound: RouteFromHarNotFoundPolicy = None, - update: bool = None, + notFound: Optional[RouteFromHarNotFoundPolicy] = None, + update: Optional[bool] = None, updateContent: Literal["attach", "embed"] = None, - updateMode: HarMode = None, + updateMode: Optional[HarMode] = None, ) -> None: if update: await self._record_into_har( @@ -467,8 +467,8 @@ async def _update_interception_patterns(self) -> None: def expect_event( self, event: str, - predicate: Callable = None, - timeout: float = None, + predicate: Optional[Callable] = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl: if timeout is None: timeout = self._timeout_settings.timeout() @@ -490,7 +490,7 @@ def _on_close(self) -> None: self._dispose_har_routers() self.emit(BrowserContext.Events.Close, self) - async def close(self, reason: str = None) -> None: + async def close(self, reason: Optional[str] = None) -> None: if self._close_was_called: return self._close_reason = reason @@ -537,7 +537,10 @@ def _effective_close_reason(self) -> Optional[str]: return None async def wait_for_event( - self, event: str, predicate: Callable = None, timeout: float = None + self, + event: str, + predicate: Optional[Callable] = None, + timeout: Optional[float] = None, ) -> Any: async with self.expect_event(event, predicate, timeout) as event_info: pass @@ -546,14 +549,14 @@ async def wait_for_event( def expect_console_message( self, predicate: Callable[[ConsoleMessage], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[ConsoleMessage]: return self.expect_event(Page.Events.Console, predicate, timeout) def expect_page( self, predicate: Callable[[Page], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[Page]: return self.expect_event(BrowserContext.Events.Page, predicate, timeout) diff --git a/playwright/_impl/_browser_type.py b/playwright/_impl/_browser_type.py index 8393d69ee..c80351e9c 100644 --- a/playwright/_impl/_browser_type.py +++ b/playwright/_impl/_browser_type.py @@ -71,21 +71,21 @@ def executable_path(self) -> str: async def launch( self, executablePath: Union[str, Path] = None, - channel: str = None, + channel: Optional[str] = None, args: Sequence[str] = None, ignoreDefaultArgs: Union[bool, Sequence[str]] = None, - handleSIGINT: bool = None, - handleSIGTERM: bool = None, - handleSIGHUP: bool = None, - timeout: float = None, - env: Env = None, - headless: bool = None, - devtools: bool = None, - proxy: ProxySettings = None, + handleSIGINT: Optional[bool] = None, + handleSIGTERM: Optional[bool] = None, + handleSIGHUP: Optional[bool] = None, + timeout: Optional[float] = None, + env: Optional[Env] = None, + headless: Optional[bool] = None, + devtools: Optional[bool] = None, + proxy: Optional[ProxySettings] = None, downloadsPath: Union[str, Path] = None, - slowMo: float = None, + slowMo: Optional[float] = None, tracesDir: Union[pathlib.Path, str] = None, - chromiumSandbox: bool = None, + chromiumSandbox: Optional[bool] = None, firefoxUserPrefs: Dict[str, Union[str, float, bool]] = None, ) -> Browser: params = locals_to_params(locals()) @@ -99,54 +99,54 @@ async def launch( async def launch_persistent_context( self, userDataDir: Union[str, Path], - channel: str = None, + channel: Optional[str] = None, executablePath: Union[str, Path] = None, args: Sequence[str] = None, ignoreDefaultArgs: Union[bool, Sequence[str]] = None, - handleSIGINT: bool = None, - handleSIGTERM: bool = None, - handleSIGHUP: bool = None, - timeout: float = None, - env: Env = None, - headless: bool = None, - devtools: bool = None, - proxy: ProxySettings = None, + handleSIGINT: Optional[bool] = None, + handleSIGTERM: Optional[bool] = None, + handleSIGHUP: Optional[bool] = None, + timeout: Optional[float] = None, + env: Optional[Env] = None, + headless: Optional[bool] = None, + devtools: Optional[bool] = None, + proxy: Optional[ProxySettings] = None, downloadsPath: Union[str, Path] = None, - slowMo: float = None, - viewport: ViewportSize = None, - screen: ViewportSize = None, - noViewport: bool = None, - ignoreHTTPSErrors: bool = None, - javaScriptEnabled: bool = None, - bypassCSP: bool = None, - userAgent: str = None, - locale: str = None, - timezoneId: str = None, - geolocation: Geolocation = None, + slowMo: Optional[float] = None, + viewport: Optional[ViewportSize] = None, + screen: Optional[ViewportSize] = None, + noViewport: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + javaScriptEnabled: Optional[bool] = None, + bypassCSP: Optional[bool] = None, + userAgent: Optional[str] = None, + locale: Optional[str] = None, + timezoneId: Optional[str] = None, + geolocation: Optional[Geolocation] = None, permissions: Sequence[str] = None, extraHTTPHeaders: Dict[str, str] = None, - offline: bool = None, - httpCredentials: HttpCredentials = None, - deviceScaleFactor: float = None, - isMobile: bool = None, - hasTouch: bool = None, - colorScheme: ColorScheme = None, - reducedMotion: ReducedMotion = None, - forcedColors: ForcedColors = None, - acceptDownloads: bool = None, + offline: Optional[bool] = None, + httpCredentials: Optional[HttpCredentials] = None, + deviceScaleFactor: Optional[float] = None, + isMobile: Optional[bool] = None, + hasTouch: Optional[bool] = None, + colorScheme: Optional[ColorScheme] = None, + reducedMotion: Optional[ReducedMotion] = None, + forcedColors: Optional[ForcedColors] = None, + acceptDownloads: Optional[bool] = None, tracesDir: Union[pathlib.Path, str] = None, - chromiumSandbox: bool = None, + chromiumSandbox: Optional[bool] = None, firefoxUserPrefs: Dict[str, Union[str, float, bool]] = None, recordHarPath: Union[Path, str] = None, - recordHarOmitContent: bool = None, + recordHarOmitContent: Optional[bool] = None, recordVideoDir: Union[Path, str] = None, - recordVideoSize: ViewportSize = None, - baseURL: str = None, - strictSelectors: bool = None, - serviceWorkers: ServiceWorkersPolicy = None, + recordVideoSize: Optional[ViewportSize] = None, + baseURL: Optional[str] = None, + strictSelectors: Optional[bool] = None, + serviceWorkers: Optional[ServiceWorkersPolicy] = None, recordHarUrlFilter: Union[Pattern[str], str] = None, - recordHarMode: HarMode = None, - recordHarContent: HarContentPolicy = None, + recordHarMode: Optional[HarMode] = None, + recordHarContent: Optional[HarContentPolicy] = None, ) -> BrowserContext: userDataDir = str(Path(userDataDir)) if userDataDir else "" params = locals_to_params(locals()) @@ -162,8 +162,8 @@ async def launch_persistent_context( async def connect_over_cdp( self, endpointURL: str, - timeout: float = None, - slowMo: float = None, + timeout: Optional[float] = None, + slowMo: Optional[float] = None, headers: Dict[str, str] = None, ) -> Browser: params = locals_to_params(locals()) @@ -184,10 +184,10 @@ async def connect_over_cdp( async def connect( self, wsEndpoint: str, - timeout: float = None, - slowMo: float = None, + timeout: Optional[float] = None, + slowMo: Optional[float] = None, headers: Dict[str, str] = None, - exposeNetwork: str = None, + exposeNetwork: Optional[str] = None, ) -> Browser: if timeout is None: timeout = 30000 diff --git a/playwright/_impl/_cdp_session.py b/playwright/_impl/_cdp_session.py index a6af32b90..7d34e3253 100644 --- a/playwright/_impl/_cdp_session.py +++ b/playwright/_impl/_cdp_session.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Any, Dict +from typing import Any, Dict, Optional from playwright._impl._connection import ChannelOwner from playwright._impl._helper import locals_to_params @@ -28,7 +28,7 @@ def __init__( def _on_event(self, params: Any) -> None: self.emit(params["method"], params["params"]) - async def send(self, method: str, params: Dict = None) -> Dict: + async def send(self, method: str, params: Optional[Dict] = None) -> Dict: return await self._channel.send("send", locals_to_params(locals())) async def detach(self) -> None: diff --git a/playwright/_impl/_connection.py b/playwright/_impl/_connection.py index f1e0dd34f..dc80764ae 100644 --- a/playwright/_impl/_connection.py +++ b/playwright/_impl/_connection.py @@ -59,17 +59,19 @@ def __init__(self, connection: "Connection", object: "ChannelOwner") -> None: self._guid = object._guid self._object = object - async def send(self, method: str, params: Dict = None) -> Any: + async def send(self, method: str, params: Optional[Dict] = None) -> Any: return await self._connection.wrap_api_call( lambda: self.inner_send(method, params, False) ) - async def send_return_as_dict(self, method: str, params: Dict = None) -> Any: + async def send_return_as_dict( + self, method: str, params: Optional[Dict] = None + ) -> Any: return await self._connection.wrap_api_call( lambda: self.inner_send(method, params, True) ) - def send_no_reply(self, method: str, params: Dict = None) -> None: + def send_no_reply(self, method: str, params: Optional[Dict] = None) -> None: # No reply messages are used to e.g. waitForEventInfo(after). self._connection.wrap_api_call_sync( lambda: self._connection._send_message_to_server( @@ -288,7 +290,7 @@ async def stop_async(self) -> None: await self._transport.wait_until_stopped() self.cleanup() - def cleanup(self, cause: Exception = None) -> None: + def cleanup(self, cause: Optional[Exception] = None) -> None: self._closed_error = ( TargetClosedError(str(cause)) if cause else TargetClosedError() ) diff --git a/playwright/_impl/_dialog.py b/playwright/_impl/_dialog.py index a0c6ca77f..c92dc1d15 100644 --- a/playwright/_impl/_dialog.py +++ b/playwright/_impl/_dialog.py @@ -47,7 +47,7 @@ def default_value(self) -> str: def page(self) -> Optional["Page"]: return self._page - async def accept(self, promptText: str = None) -> None: + async def accept(self, promptText: Optional[str] = None) -> None: await self._channel.send("accept", locals_to_params(locals())) async def dismiss(self) -> None: diff --git a/playwright/_impl/_element_handle.py b/playwright/_impl/_element_handle.py index 558cf3ac9..eb39b98f5 100644 --- a/playwright/_impl/_element_handle.py +++ b/playwright/_impl/_element_handle.py @@ -103,49 +103,49 @@ async def is_hidden(self) -> bool: async def is_visible(self) -> bool: return await self._channel.send("isVisible") - async def dispatch_event(self, type: str, eventInit: Dict = None) -> None: + async def dispatch_event(self, type: str, eventInit: Optional[Dict] = None) -> None: await self._channel.send( "dispatchEvent", dict(type=type, eventInit=serialize_argument(eventInit)) ) - async def scroll_into_view_if_needed(self, timeout: float = None) -> None: + async def scroll_into_view_if_needed(self, timeout: Optional[float] = None) -> None: await self._channel.send("scrollIntoViewIfNeeded", locals_to_params(locals())) async def hover( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("hover", locals_to_params(locals())) async def click( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - clickCount: int = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + clickCount: Optional[int] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("click", locals_to_params(locals())) async def dblclick( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("dblclick", locals_to_params(locals())) @@ -155,9 +155,9 @@ async def select_option( index: Union[int, Sequence[int]] = None, label: Union[str, Sequence[str]] = None, element: Union["ElementHandle", Sequence["ElementHandle"]] = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, ) -> List[str]: params = locals_to_params( dict( @@ -172,27 +172,29 @@ async def select_option( async def tap( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("tap", locals_to_params(locals())) async def fill( self, value: str, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, ) -> None: await self._channel.send("fill", locals_to_params(locals())) - async def select_text(self, force: bool = None, timeout: float = None) -> None: + async def select_text( + self, force: Optional[bool] = None, timeout: Optional[float] = None + ) -> None: await self._channel.send("selectText", locals_to_params(locals())) - async def input_value(self, timeout: float = None) -> str: + async def input_value(self, timeout: Optional[float] = None) -> str: return await self._channel.send("inputValue", locals_to_params(locals())) async def set_input_files( @@ -200,8 +202,8 @@ async def set_input_files( files: Union[ str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload] ], - timeout: float = None, - noWaitAfter: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: frame = await self.owner_frame() if not frame: @@ -222,29 +224,29 @@ async def focus(self) -> None: async def type( self, text: str, - delay: float = None, - timeout: float = None, - noWaitAfter: bool = None, + delay: Optional[float] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: await self._channel.send("type", locals_to_params(locals())) async def press( self, key: str, - delay: float = None, - timeout: float = None, - noWaitAfter: bool = None, + delay: Optional[float] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: await self._channel.send("press", locals_to_params(locals())) async def set_checked( self, checked: bool, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: if checked: await self.check( @@ -265,21 +267,21 @@ async def set_checked( async def check( self, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("check", locals_to_params(locals())) async def uncheck( self, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("uncheck", locals_to_params(locals())) @@ -288,17 +290,17 @@ async def bounding_box(self) -> Optional[FloatRect]: async def screenshot( self, - timeout: float = None, + timeout: Optional[float] = None, type: Literal["jpeg", "png"] = None, path: Union[str, Path] = None, - quality: int = None, - omitBackground: bool = None, + quality: Optional[int] = None, + omitBackground: Optional[bool] = None, animations: Literal["allow", "disabled"] = None, caret: Literal["hide", "initial"] = None, scale: Literal["css", "device"] = None, mask: Sequence["Locator"] = None, - maskColor: str = None, - style: str = None, + maskColor: Optional[str] = None, + style: Optional[str] = None, ) -> bytes: params = locals_to_params(locals()) if "path" in params: @@ -339,7 +341,7 @@ async def eval_on_selector( self, selector: str, expression: str, - arg: Serializable = None, + arg: Optional[Serializable] = None, ) -> Any: return parse_result( await self._channel.send( @@ -356,7 +358,7 @@ async def eval_on_selector_all( self, selector: str, expression: str, - arg: Serializable = None, + arg: Optional[Serializable] = None, ) -> Any: return parse_result( await self._channel.send( @@ -374,7 +376,7 @@ async def wait_for_element_state( state: Literal[ "disabled", "editable", "enabled", "hidden", "stable", "visible" ], - timeout: float = None, + timeout: Optional[float] = None, ) -> None: await self._channel.send("waitForElementState", locals_to_params(locals())) @@ -382,8 +384,8 @@ async def wait_for_selector( self, selector: str, state: Literal["attached", "detached", "hidden", "visible"] = None, - timeout: float = None, - strict: bool = None, + timeout: Optional[float] = None, + strict: Optional[bool] = None, ) -> Optional["ElementHandle"]: return from_nullable_channel( await self._channel.send("waitForSelector", locals_to_params(locals())) @@ -399,8 +401,8 @@ def convert_select_option_values( if value is None and index is None and label is None and element is None: return {} - options: Any = None - elements: Any = None + options: Optional[Any] = None + elements: Optional[Any] = None if value: if isinstance(value, str): value = [value] diff --git a/playwright/_impl/_errors.py b/playwright/_impl/_errors.py index e052d25bf..7796125f6 100644 --- a/playwright/_impl/_errors.py +++ b/playwright/_impl/_errors.py @@ -49,5 +49,5 @@ class TimeoutError(Error, TimeoutErrorBuiltin): class TargetClosedError(Error): - def __init__(self, message: str = None) -> None: + def __init__(self, message: Optional[str] = None) -> None: super().__init__(message or "Target page, context or browser has been closed") diff --git a/playwright/_impl/_fetch.py b/playwright/_impl/_fetch.py index 53c457ba7..2b62014f1 100644 --- a/playwright/_impl/_fetch.py +++ b/playwright/_impl/_fetch.py @@ -62,13 +62,13 @@ def __init__(self, playwright: "Playwright") -> None: async def new_context( self, - baseURL: str = None, + baseURL: Optional[str] = None, extraHTTPHeaders: Dict[str, str] = None, - httpCredentials: HttpCredentials = None, - ignoreHTTPSErrors: bool = None, - proxy: ProxySettings = None, - userAgent: str = None, - timeout: float = None, + httpCredentials: Optional[HttpCredentials] = None, + ignoreHTTPSErrors: Optional[bool] = None, + proxy: Optional[ProxySettings] = None, + userAgent: Optional[str] = None, + timeout: Optional[float] = None, storageState: Union[StorageState, str, Path] = None, ) -> "APIRequestContext": params = locals_to_params(locals()) @@ -100,15 +100,15 @@ async def dispose(self) -> None: async def delete( self, url: str, - params: ParamsType = None, - headers: Headers = None, - data: DataType = None, - form: FormType = None, - multipart: MultipartType = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + params: Optional[ParamsType] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + form: Optional[FormType] = None, + multipart: Optional[MultipartType] = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": return await self.fetch( url, @@ -127,15 +127,15 @@ async def delete( async def head( self, url: str, - params: ParamsType = None, - headers: Headers = None, - data: DataType = None, - form: FormType = None, - multipart: MultipartType = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + params: Optional[ParamsType] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + form: Optional[FormType] = None, + multipart: Optional[MultipartType] = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": return await self.fetch( url, @@ -154,15 +154,15 @@ async def head( async def get( self, url: str, - params: ParamsType = None, - headers: Headers = None, - data: DataType = None, - form: FormType = None, - multipart: MultipartType = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + params: Optional[ParamsType] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + form: Optional[FormType] = None, + multipart: Optional[MultipartType] = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": return await self.fetch( url, @@ -181,15 +181,15 @@ async def get( async def patch( self, url: str, - params: ParamsType = None, - headers: Headers = None, - data: DataType = None, - form: FormType = None, + params: Optional[ParamsType] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + form: Optional[FormType] = None, multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": return await self.fetch( url, @@ -208,15 +208,15 @@ async def patch( async def put( self, url: str, - params: ParamsType = None, - headers: Headers = None, - data: DataType = None, - form: FormType = None, + params: Optional[ParamsType] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + form: Optional[FormType] = None, multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": return await self.fetch( url, @@ -235,15 +235,15 @@ async def put( async def post( self, url: str, - params: ParamsType = None, - headers: Headers = None, - data: DataType = None, - form: FormType = None, + params: Optional[ParamsType] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + form: Optional[FormType] = None, multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": return await self.fetch( url, @@ -262,16 +262,16 @@ async def post( async def fetch( self, urlOrRequest: Union[str, network.Request], - params: ParamsType = None, - method: str = None, - headers: Headers = None, - data: DataType = None, - form: FormType = None, + params: Optional[ParamsType] = None, + method: Optional[str] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + form: Optional[FormType] = None, multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": url = urlOrRequest if isinstance(urlOrRequest, str) else None request = ( @@ -301,16 +301,16 @@ async def _inner_fetch( self, request: Optional[network.Request], url: Optional[str], - method: str = None, - headers: Headers = None, - data: DataType = None, - params: ParamsType = None, - form: FormType = None, + method: Optional[str] = None, + headers: Optional[Headers] = None, + data: Optional[DataType] = None, + params: Optional[ParamsType] = None, + form: Optional[FormType] = None, multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = None, - timeout: float = None, - failOnStatusCode: bool = None, - ignoreHTTPSErrors: bool = None, - maxRedirects: int = None, + timeout: Optional[float] = None, + failOnStatusCode: Optional[bool] = None, + ignoreHTTPSErrors: Optional[bool] = None, + maxRedirects: Optional[int] = None, ) -> "APIResponse": assert ( (1 if data else 0) + (1 if form else 0) + (1 if multipart else 0) @@ -323,7 +323,7 @@ async def _inner_fetch( # Cannot call allHeaders() here as the request may be paused inside route handler. headers_obj = headers or (request.headers if request else None) serialized_headers = serialize_headers(headers_obj) if headers_obj else None - json_data: Any = None + json_data: Optional[Any] = None form_data: Optional[List[NameValue]] = None multipart_data: Optional[List[FormField]] = None post_data_buffer: Optional[bytes] = None diff --git a/playwright/_impl/_file_chooser.py b/playwright/_impl/_file_chooser.py index 951919d22..c137ec44a 100644 --- a/playwright/_impl/_file_chooser.py +++ b/playwright/_impl/_file_chooser.py @@ -13,7 +13,7 @@ # limitations under the License. from pathlib import Path -from typing import TYPE_CHECKING, Sequence, Union +from typing import TYPE_CHECKING, Optional, Sequence, Union from playwright._impl._api_structures import FilePayload @@ -51,7 +51,7 @@ async def set_files( files: Union[ str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload] ], - timeout: float = None, - noWaitAfter: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: await self._element_handle.set_input_files(files, timeout, noWaitAfter) diff --git a/playwright/_impl/_frame.py b/playwright/_impl/_frame.py index 75047ff79..49319831c 100644 --- a/playwright/_impl/_frame.py +++ b/playwright/_impl/_frame.py @@ -109,7 +109,9 @@ def __repr__(self) -> str: return f"" def _on_load_state( - self, add: DocumentLoadState = None, remove: DocumentLoadState = None + self, + add: Optional[DocumentLoadState] = None, + remove: Optional[DocumentLoadState] = None, ) -> None: if add: self._load_states.add(add) @@ -139,9 +141,9 @@ def page(self) -> "Page": async def goto( self, url: str, - timeout: float = None, - waitUntil: DocumentLoadState = None, - referer: str = None, + timeout: Optional[float] = None, + waitUntil: Optional[DocumentLoadState] = None, + referer: Optional[str] = None, ) -> Optional[Response]: return cast( Optional[Response], @@ -150,7 +152,9 @@ async def goto( ), ) - def _setup_navigation_waiter(self, wait_name: str, timeout: float = None) -> Waiter: + def _setup_navigation_waiter( + self, wait_name: str, timeout: Optional[float] = None + ) -> Waiter: assert self._page waiter = Waiter(self._page, f"frame.{wait_name}") waiter.reject_on_event( @@ -174,9 +178,9 @@ def _setup_navigation_waiter(self, wait_name: str, timeout: float = None) -> Wai def expect_navigation( self, - url: URLMatch = None, - waitUntil: DocumentLoadState = None, - timeout: float = None, + url: Optional[URLMatch] = None, + waitUntil: Optional[DocumentLoadState] = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[Response]: assert self._page if not waitUntil: @@ -226,8 +230,8 @@ async def continuation() -> Optional[Response]: async def wait_for_url( self, url: URLMatch, - waitUntil: DocumentLoadState = None, - timeout: float = None, + waitUntil: Optional[DocumentLoadState] = None, + timeout: Optional[float] = None, ) -> None: assert self._page matcher = URLMatcher(self._page._browser_context._options.get("baseURL"), url) @@ -242,12 +246,12 @@ async def wait_for_url( async def wait_for_load_state( self, state: Literal["domcontentloaded", "load", "networkidle"] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: return await self._wait_for_load_state_impl(state, timeout) async def _wait_for_load_state_impl( - self, state: DocumentLoadState = None, timeout: float = None + self, state: Optional[DocumentLoadState] = None, timeout: Optional[float] = None ) -> None: if not state: state = "load" @@ -277,7 +281,9 @@ def handle_load_state_event(actual_state: str) -> bool: async def frame_element(self) -> ElementHandle: return from_channel(await self._channel.send("frameElement")) - async def evaluate(self, expression: str, arg: Serializable = None) -> Any: + async def evaluate( + self, expression: str, arg: Optional[Serializable] = None + ) -> Any: return parse_result( await self._channel.send( "evaluateExpression", @@ -289,7 +295,7 @@ async def evaluate(self, expression: str, arg: Serializable = None) -> Any: ) async def evaluate_handle( - self, expression: str, arg: Serializable = None + self, expression: str, arg: Optional[Serializable] = None ) -> JSHandle: return from_channel( await self._channel.send( @@ -302,7 +308,7 @@ async def evaluate_handle( ) async def query_selector( - self, selector: str, strict: bool = None + self, selector: str, strict: Optional[bool] = None ) -> Optional[ElementHandle]: return from_nullable_channel( await self._channel.send("querySelector", locals_to_params(locals())) @@ -319,8 +325,8 @@ async def query_selector_all(self, selector: str) -> List[ElementHandle]: async def wait_for_selector( self, selector: str, - strict: bool = None, - timeout: float = None, + strict: Optional[bool] = None, + timeout: Optional[float] = None, state: Literal["attached", "detached", "hidden", "visible"] = None, ) -> Optional[ElementHandle]: return from_nullable_channel( @@ -328,32 +334,50 @@ async def wait_for_selector( ) async def is_checked( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._channel.send("isChecked", locals_to_params(locals())) async def is_disabled( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._channel.send("isDisabled", locals_to_params(locals())) async def is_editable( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._channel.send("isEditable", locals_to_params(locals())) async def is_enabled( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._channel.send("isEnabled", locals_to_params(locals())) async def is_hidden( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._channel.send("isHidden", locals_to_params(locals())) async def is_visible( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._channel.send("isVisible", locals_to_params(locals())) @@ -361,9 +385,9 @@ async def dispatch_event( self, selector: str, type: str, - eventInit: Dict = None, - strict: bool = None, - timeout: float = None, + eventInit: Optional[Dict] = None, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: await self._channel.send( "dispatchEvent", @@ -382,8 +406,8 @@ async def eval_on_selector( self, selector: str, expression: str, - arg: Serializable = None, - strict: bool = None, + arg: Optional[Serializable] = None, + strict: Optional[bool] = None, ) -> Any: return parse_result( await self._channel.send( @@ -403,7 +427,7 @@ async def eval_on_selector_all( self, selector: str, expression: str, - arg: Serializable = None, + arg: Optional[Serializable] = None, ) -> Any: return parse_result( await self._channel.send( @@ -422,8 +446,8 @@ async def content(self) -> str: async def set_content( self, html: str, - timeout: float = None, - waitUntil: DocumentLoadState = None, + timeout: Optional[float] = None, + waitUntil: Optional[DocumentLoadState] = None, ) -> None: await self._channel.send("setContent", locals_to_params(locals())) @@ -448,10 +472,10 @@ def is_detached(self) -> bool: async def add_script_tag( self, - url: str = None, + url: Optional[str] = None, path: Union[str, Path] = None, - content: str = None, - type: str = None, + content: Optional[str] = None, + type: Optional[str] = None, ) -> ElementHandle: params = locals_to_params(locals()) if path: @@ -464,7 +488,10 @@ async def add_script_tag( return from_channel(await self._channel.send("addScriptTag", params)) async def add_style_tag( - self, url: str = None, path: Union[str, Path] = None, content: str = None + self, + url: Optional[str] = None, + path: Union[str, Path] = None, + content: Optional[str] = None, ) -> ElementHandle: params = locals_to_params(locals()) if path: @@ -481,15 +508,15 @@ async def click( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - clickCount: int = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + clickCount: Optional[int] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("click", locals_to_params(locals())) @@ -497,14 +524,14 @@ async def dblclick( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("dblclick", locals_to_params(locals())) @@ -512,12 +539,12 @@ async def tap( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("tap", locals_to_params(locals())) @@ -525,10 +552,10 @@ async def fill( self, selector: str, value: str, - timeout: float = None, - noWaitAfter: bool = None, - strict: bool = None, - force: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + force: Optional[bool] = None, ) -> None: await self._channel.send("fill", locals_to_params(locals())) @@ -537,8 +564,8 @@ def locator( selector: str, hasText: Union[str, Pattern[str]] = None, hasNotText: Union[str, Pattern[str]] = None, - has: Locator = None, - hasNot: Locator = None, + has: Optional[Locator] = None, + hasNot: Optional[Locator] = None, ) -> Locator: return Locator( self, @@ -550,32 +577,32 @@ def locator( ) def get_by_alt_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_alt_text_selector(text, exact=exact)) def get_by_label( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_label_selector(text, exact=exact)) def get_by_placeholder( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_placeholder_selector(text, exact=exact)) def get_by_role( self, role: AriaRole, - checked: bool = None, - disabled: bool = None, - expanded: bool = None, - includeHidden: bool = None, - level: int = None, + checked: Optional[bool] = None, + disabled: Optional[bool] = None, + expanded: Optional[bool] = None, + includeHidden: Optional[bool] = None, + level: Optional[int] = None, name: Union[str, Pattern[str]] = None, - pressed: bool = None, - selected: bool = None, - exact: bool = None, + pressed: Optional[bool] = None, + selected: Optional[bool] = None, + exact: Optional[bool] = None, ) -> "Locator": return self.locator( get_by_role_selector( @@ -596,12 +623,12 @@ def get_by_test_id(self, testId: Union[str, Pattern[str]]) -> "Locator": return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId)) def get_by_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_text_selector(text, exact=exact)) def get_by_title( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_title_selector(text, exact=exact)) @@ -609,27 +636,43 @@ def frame_locator(self, selector: str) -> FrameLocator: return FrameLocator(self, selector) async def focus( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: await self._channel.send("focus", locals_to_params(locals())) async def text_content( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> Optional[str]: return await self._channel.send("textContent", locals_to_params(locals())) async def inner_text( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> str: return await self._channel.send("innerText", locals_to_params(locals())) async def inner_html( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> str: return await self._channel.send("innerHTML", locals_to_params(locals())) async def get_attribute( - self, selector: str, name: str, strict: bool = None, timeout: float = None + self, + selector: str, + name: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> Optional[str]: return await self._channel.send("getAttribute", locals_to_params(locals())) @@ -637,12 +680,12 @@ async def hover( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("hover", locals_to_params(locals())) @@ -650,13 +693,13 @@ async def drag_and_drop( self, source: str, target: str, - sourcePosition: Position = None, - targetPosition: Position = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - timeout: float = None, - trial: bool = None, + sourcePosition: Optional[Position] = None, + targetPosition: Optional[Position] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + timeout: Optional[float] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("dragAndDrop", locals_to_params(locals())) @@ -667,10 +710,10 @@ async def select_option( index: Union[int, Sequence[int]] = None, label: Union[str, Sequence[str]] = None, element: Union["ElementHandle", Sequence["ElementHandle"]] = None, - timeout: float = None, - noWaitAfter: bool = None, - strict: bool = None, - force: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + force: Optional[bool] = None, ) -> List[str]: params = locals_to_params( dict( @@ -687,8 +730,8 @@ async def select_option( async def input_value( self, selector: str, - strict: bool = None, - timeout: float = None, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> str: return await self._channel.send("inputValue", locals_to_params(locals())) @@ -698,9 +741,9 @@ async def set_input_files( files: Union[ str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload] ], - strict: bool = None, - timeout: float = None, - noWaitAfter: bool = None, + strict: Optional[bool] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: converted = await convert_input_files(files, self.page.context) await self._channel.send( @@ -718,10 +761,10 @@ async def type( self, selector: str, text: str, - delay: float = None, - strict: bool = None, - timeout: float = None, - noWaitAfter: bool = None, + delay: Optional[float] = None, + strict: Optional[bool] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: await self._channel.send("type", locals_to_params(locals())) @@ -729,34 +772,34 @@ async def press( self, selector: str, key: str, - delay: float = None, - strict: bool = None, - timeout: float = None, - noWaitAfter: bool = None, + delay: Optional[float] = None, + strict: Optional[bool] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: await self._channel.send("press", locals_to_params(locals())) async def check( self, selector: str, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("check", locals_to_params(locals())) async def uncheck( self, selector: str, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: await self._channel.send("uncheck", locals_to_params(locals())) @@ -766,8 +809,8 @@ async def wait_for_timeout(self, timeout: float) -> None: async def wait_for_function( self, expression: str, - arg: Serializable = None, - timeout: float = None, + arg: Optional[Serializable] = None, + timeout: Optional[float] = None, polling: Union[float, Literal["raf"]] = None, ) -> JSHandle: if isinstance(polling, str) and polling != "raf": @@ -785,12 +828,12 @@ async def set_checked( self, selector: str, checked: bool, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: if checked: await self.check( diff --git a/playwright/_impl/_helper.py b/playwright/_impl/_helper.py index 615cd5264..1cf2e0897 100644 --- a/playwright/_impl/_helper.py +++ b/playwright/_impl/_helper.py @@ -182,7 +182,7 @@ def __init__(self, parent: Optional["TimeoutSettings"]) -> None: def set_default_timeout(self, timeout: Optional[float]) -> None: self._default_timeout = timeout - def timeout(self, timeout: float = None) -> float: + def timeout(self, timeout: Optional[float] = None) -> float: if timeout is not None: return timeout if self._default_timeout is not None: diff --git a/playwright/_impl/_impl_to_api_mapping.py b/playwright/_impl/_impl_to_api_mapping.py index 4315e1868..d69f27667 100644 --- a/playwright/_impl/_impl_to_api_mapping.py +++ b/playwright/_impl/_impl_to_api_mapping.py @@ -78,7 +78,7 @@ def from_impl(self, obj: Any) -> Any: assert result return result - def from_impl_nullable(self, obj: Any = None) -> Optional[Any]: + def from_impl_nullable(self, obj: Optional[Any] = None) -> Optional[Any]: return self.from_impl(obj) if obj else None def from_impl_list(self, items: Sequence[Any]) -> List[Any]: diff --git a/playwright/_impl/_input.py b/playwright/_impl/_input.py index a97ba5d11..610e3d765 100644 --- a/playwright/_impl/_input.py +++ b/playwright/_impl/_input.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from typing import Optional + from playwright._impl._connection import Channel from playwright._impl._helper import MouseButton, locals_to_params @@ -31,10 +33,10 @@ async def up(self, key: str) -> None: async def insert_text(self, text: str) -> None: await self._channel.send("keyboardInsertText", locals_to_params(locals())) - async def type(self, text: str, delay: float = None) -> None: + async def type(self, text: str, delay: Optional[float] = None) -> None: await self._channel.send("keyboardType", locals_to_params(locals())) - async def press(self, key: str, delay: float = None) -> None: + async def press(self, key: str, delay: Optional[float] = None) -> None: await self._channel.send("keyboardPress", locals_to_params(locals())) @@ -44,20 +46,20 @@ def __init__(self, channel: Channel) -> None: self._loop = channel._connection._loop self._dispatcher_fiber = channel._connection._dispatcher_fiber - async def move(self, x: float, y: float, steps: int = None) -> None: + async def move(self, x: float, y: float, steps: Optional[int] = None) -> None: await self._channel.send("mouseMove", locals_to_params(locals())) async def down( self, - button: MouseButton = None, - clickCount: int = None, + button: Optional[MouseButton] = None, + clickCount: Optional[int] = None, ) -> None: await self._channel.send("mouseDown", locals_to_params(locals())) async def up( self, - button: MouseButton = None, - clickCount: int = None, + button: Optional[MouseButton] = None, + clickCount: Optional[int] = None, ) -> None: await self._channel.send("mouseUp", locals_to_params(locals())) @@ -65,9 +67,9 @@ async def click( self, x: float, y: float, - delay: float = None, - button: MouseButton = None, - clickCount: int = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + clickCount: Optional[int] = None, ) -> None: await self._channel.send("mouseClick", locals_to_params(locals())) @@ -75,8 +77,8 @@ async def dblclick( self, x: float, y: float, - delay: float = None, - button: MouseButton = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, ) -> None: await self.click(x, y, delay=delay, button=button, clickCount=2) diff --git a/playwright/_impl/_js_handle.py b/playwright/_impl/_js_handle.py index 4bd8146b1..878809a7a 100644 --- a/playwright/_impl/_js_handle.py +++ b/playwright/_impl/_js_handle.py @@ -62,7 +62,9 @@ def __str__(self) -> str: def _on_preview_updated(self, preview: str) -> None: self._preview = preview - async def evaluate(self, expression: str, arg: Serializable = None) -> Any: + async def evaluate( + self, expression: str, arg: Optional[Serializable] = None + ) -> Any: return parse_result( await self._channel.send( "evaluateExpression", @@ -74,7 +76,7 @@ async def evaluate(self, expression: str, arg: Serializable = None) -> Any: ) async def evaluate_handle( - self, expression: str, arg: Serializable = None + self, expression: str, arg: Optional[Serializable] = None ) -> "JSHandle": return from_channel( await self._channel.send( @@ -159,7 +161,7 @@ def serialize_value( return dict(v="undefined") -def serialize_argument(arg: Serializable = None) -> Any: +def serialize_argument(arg: Optional[Serializable] = None) -> Any: handles: List[Channel] = [] value = serialize_value(arg, handles) return dict(value=value, handles=handles) diff --git a/playwright/_impl/_locator.py b/playwright/_impl/_locator.py index a9cc92aba..877f36967 100644 --- a/playwright/_impl/_locator.py +++ b/playwright/_impl/_locator.py @@ -106,7 +106,7 @@ def __repr__(self) -> str: async def _with_element( self, task: Callable[[ElementHandle, float], Awaitable[T]], - timeout: float = None, + timeout: Optional[float] = None, ) -> T: timeout = self._frame.page._timeout_settings.timeout(timeout) deadline = (monotonic_time() + timeout) if timeout else 0 @@ -125,7 +125,9 @@ async def _with_element( def page(self) -> "Page": return self._frame.page - async def bounding_box(self, timeout: float = None) -> Optional[FloatRect]: + async def bounding_box( + self, timeout: Optional[float] = None + ) -> Optional[FloatRect]: return await self._with_element( lambda h, _: h.bounding_box(), timeout, @@ -133,11 +135,11 @@ async def bounding_box(self, timeout: float = None) -> Optional[FloatRect]: async def check( self, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.check(self._selector, strict=True, **params) @@ -145,14 +147,14 @@ async def check( async def click( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - clickCount: int = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + clickCount: Optional[int] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.click(self._selector, strict=True, **params) @@ -160,13 +162,13 @@ async def click( async def dblclick( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.dblclick(self._selector, strict=True, **params) @@ -174,26 +176,34 @@ async def dblclick( async def dispatch_event( self, type: str, - eventInit: Dict = None, - timeout: float = None, + eventInit: Optional[Dict] = None, + timeout: Optional[float] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.dispatch_event(self._selector, strict=True, **params) async def evaluate( - self, expression: str, arg: Serializable = None, timeout: float = None + self, + expression: str, + arg: Optional[Serializable] = None, + timeout: Optional[float] = None, ) -> Any: return await self._with_element( lambda h, _: h.evaluate(expression, arg), timeout, ) - async def evaluate_all(self, expression: str, arg: Serializable = None) -> Any: + async def evaluate_all( + self, expression: str, arg: Optional[Serializable] = None + ) -> Any: params = locals_to_params(locals()) return await self._frame.eval_on_selector_all(self._selector, **params) async def evaluate_handle( - self, expression: str, arg: Serializable = None, timeout: float = None + self, + expression: str, + arg: Optional[Serializable] = None, + timeout: Optional[float] = None, ) -> "JSHandle": return await self._with_element( lambda h, _: h.evaluate_handle(expression, arg), timeout @@ -202,18 +212,18 @@ async def evaluate_handle( async def fill( self, value: str, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.fill(self._selector, strict=True, **params) async def clear( self, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, ) -> None: await self.fill("", timeout=timeout, noWaitAfter=noWaitAfter, force=force) @@ -247,32 +257,32 @@ def locator( ) def get_by_alt_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_alt_text_selector(text, exact=exact)) def get_by_label( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_label_selector(text, exact=exact)) def get_by_placeholder( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_placeholder_selector(text, exact=exact)) def get_by_role( self, role: AriaRole, - checked: bool = None, - disabled: bool = None, - expanded: bool = None, - includeHidden: bool = None, - level: int = None, + checked: Optional[bool] = None, + disabled: Optional[bool] = None, + expanded: Optional[bool] = None, + includeHidden: Optional[bool] = None, + level: Optional[int] = None, name: Union[str, Pattern[str]] = None, - pressed: bool = None, - selected: bool = None, - exact: bool = None, + pressed: Optional[bool] = None, + selected: Optional[bool] = None, + exact: Optional[bool] = None, ) -> "Locator": return self.locator( get_by_role_selector( @@ -293,12 +303,12 @@ def get_by_test_id(self, testId: Union[str, Pattern[str]]) -> "Locator": return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId)) def get_by_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_text_selector(text, exact=exact)) def get_by_title( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_title_selector(text, exact=exact)) @@ -307,7 +317,7 @@ def frame_locator(self, selector: str) -> "FrameLocator": async def element_handle( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> ElementHandle: params = locals_to_params(locals()) handle = await self._frame.wait_for_selector( @@ -362,11 +372,11 @@ def and_(self, locator: "Locator") -> "Locator": self._selector + " >> internal:and=" + json.dumps(locator._selector), ) - async def focus(self, timeout: float = None) -> None: + async def focus(self, timeout: Optional[float] = None) -> None: params = locals_to_params(locals()) return await self._frame.focus(self._selector, strict=True, **params) - async def blur(self, timeout: float = None) -> None: + async def blur(self, timeout: Optional[float] = None) -> None: await self._frame._channel.send( "blur", { @@ -392,12 +402,12 @@ async def count( async def drag_to( self, target: "Locator", - force: bool = None, - noWaitAfter: bool = None, - timeout: float = None, - trial: bool = None, - sourcePosition: Position = None, - targetPosition: Position = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + timeout: Optional[float] = None, + trial: Optional[bool] = None, + sourcePosition: Optional[Position] = None, + targetPosition: Optional[Position] = None, ) -> None: params = locals_to_params(locals()) del params["target"] @@ -405,7 +415,9 @@ async def drag_to( self._selector, target._selector, strict=True, **params ) - async def get_attribute(self, name: str, timeout: float = None) -> Optional[str]: + async def get_attribute( + self, name: str, timeout: Optional[float] = None + ) -> Optional[str]: params = locals_to_params(locals()) return await self._frame.get_attribute( self._selector, @@ -416,11 +428,11 @@ async def get_attribute(self, name: str, timeout: float = None) -> Optional[str] async def hover( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.hover( @@ -429,7 +441,7 @@ async def hover( **params, ) - async def inner_html(self, timeout: float = None) -> str: + async def inner_html(self, timeout: Optional[float] = None) -> str: params = locals_to_params(locals()) return await self._frame.inner_html( self._selector, @@ -437,7 +449,7 @@ async def inner_html(self, timeout: float = None) -> str: **params, ) - async def inner_text(self, timeout: float = None) -> str: + async def inner_text(self, timeout: Optional[float] = None) -> str: params = locals_to_params(locals()) return await self._frame.inner_text( self._selector, @@ -445,7 +457,7 @@ async def inner_text(self, timeout: float = None) -> str: **params, ) - async def input_value(self, timeout: float = None) -> str: + async def input_value(self, timeout: Optional[float] = None) -> str: params = locals_to_params(locals()) return await self._frame.input_value( self._selector, @@ -453,7 +465,7 @@ async def input_value(self, timeout: float = None) -> str: **params, ) - async def is_checked(self, timeout: float = None) -> bool: + async def is_checked(self, timeout: Optional[float] = None) -> bool: params = locals_to_params(locals()) return await self._frame.is_checked( self._selector, @@ -461,7 +473,7 @@ async def is_checked(self, timeout: float = None) -> bool: **params, ) - async def is_disabled(self, timeout: float = None) -> bool: + async def is_disabled(self, timeout: Optional[float] = None) -> bool: params = locals_to_params(locals()) return await self._frame.is_disabled( self._selector, @@ -469,7 +481,7 @@ async def is_disabled(self, timeout: float = None) -> bool: **params, ) - async def is_editable(self, timeout: float = None) -> bool: + async def is_editable(self, timeout: Optional[float] = None) -> bool: params = locals_to_params(locals()) return await self._frame.is_editable( self._selector, @@ -477,7 +489,7 @@ async def is_editable(self, timeout: float = None) -> bool: **params, ) - async def is_enabled(self, timeout: float = None) -> bool: + async def is_enabled(self, timeout: Optional[float] = None) -> bool: params = locals_to_params(locals()) return await self._frame.is_editable( self._selector, @@ -485,7 +497,7 @@ async def is_enabled(self, timeout: float = None) -> bool: **params, ) - async def is_hidden(self, timeout: float = None) -> bool: + async def is_hidden(self, timeout: Optional[float] = None) -> bool: params = locals_to_params(locals()) return await self._frame.is_hidden( self._selector, @@ -493,7 +505,7 @@ async def is_hidden(self, timeout: float = None) -> bool: **params, ) - async def is_visible(self, timeout: float = None) -> bool: + async def is_visible(self, timeout: Optional[float] = None) -> bool: params = locals_to_params(locals()) return await self._frame.is_visible( self._selector, @@ -504,26 +516,26 @@ async def is_visible(self, timeout: float = None) -> bool: async def press( self, key: str, - delay: float = None, - timeout: float = None, - noWaitAfter: bool = None, + delay: Optional[float] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.press(self._selector, strict=True, **params) async def screenshot( self, - timeout: float = None, + timeout: Optional[float] = None, type: Literal["jpeg", "png"] = None, path: Union[str, pathlib.Path] = None, - quality: int = None, - omitBackground: bool = None, + quality: Optional[int] = None, + omitBackground: Optional[bool] = None, animations: Literal["allow", "disabled"] = None, caret: Literal["hide", "initial"] = None, scale: Literal["css", "device"] = None, mask: Sequence["Locator"] = None, - maskColor: str = None, - style: str = None, + maskColor: Optional[str] = None, + style: Optional[str] = None, ) -> bytes: params = locals_to_params(locals()) return await self._with_element( @@ -534,7 +546,7 @@ async def screenshot( async def scroll_into_view_if_needed( self, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: return await self._with_element( lambda h, timeout: h.scroll_into_view_if_needed(timeout=timeout), @@ -547,9 +559,9 @@ async def select_option( index: Union[int, Sequence[int]] = None, label: Union[str, Sequence[str]] = None, element: Union["ElementHandle", Sequence["ElementHandle"]] = None, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, ) -> List[str]: params = locals_to_params(locals()) return await self._frame.select_option( @@ -558,7 +570,9 @@ async def select_option( **params, ) - async def select_text(self, force: bool = None, timeout: float = None) -> None: + async def select_text( + self, force: Optional[bool] = None, timeout: Optional[float] = None + ) -> None: params = locals_to_params(locals()) return await self._with_element( lambda h, timeout: h.select_text(**{**params, "timeout": timeout}), @@ -574,8 +588,8 @@ async def set_input_files( Sequence[Union[str, pathlib.Path]], Sequence[FilePayload], ], - timeout: float = None, - noWaitAfter: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.set_input_files( @@ -587,11 +601,11 @@ async def set_input_files( async def tap( self, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.tap( @@ -600,7 +614,7 @@ async def tap( **params, ) - async def text_content(self, timeout: float = None) -> Optional[str]: + async def text_content(self, timeout: Optional[float] = None) -> Optional[str]: params = locals_to_params(locals()) return await self._frame.text_content( self._selector, @@ -611,9 +625,9 @@ async def text_content(self, timeout: float = None) -> Optional[str]: async def type( self, text: str, - delay: float = None, - timeout: float = None, - noWaitAfter: bool = None, + delay: Optional[float] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.type( @@ -625,19 +639,19 @@ async def type( async def press_sequentially( self, text: str, - delay: float = None, - timeout: float = None, - noWaitAfter: bool = None, + delay: Optional[float] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, ) -> None: await self.type(text, delay=delay, timeout=timeout, noWaitAfter=noWaitAfter) async def uncheck( self, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) return await self._frame.uncheck( @@ -662,7 +676,7 @@ async def all_text_contents( async def wait_for( self, - timeout: float = None, + timeout: Optional[float] = None, state: Literal["attached", "detached", "hidden", "visible"] = None, ) -> None: await self._frame.wait_for_selector( @@ -672,11 +686,11 @@ async def wait_for( async def set_checked( self, checked: bool, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: if checked: await self.check( @@ -728,8 +742,8 @@ def locator( selectorOrLocator: Union["Locator", str], hasText: Union[str, Pattern[str]] = None, hasNotText: Union[str, Pattern[str]] = None, - has: Locator = None, - hasNot: Locator = None, + has: Optional[Locator] = None, + hasNot: Optional[Locator] = None, ) -> Locator: if isinstance(selectorOrLocator, str): return Locator( @@ -753,32 +767,32 @@ def locator( ) def get_by_alt_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_alt_text_selector(text, exact=exact)) def get_by_label( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_label_selector(text, exact=exact)) def get_by_placeholder( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_placeholder_selector(text, exact=exact)) def get_by_role( self, role: AriaRole, - checked: bool = None, - disabled: bool = None, - expanded: bool = None, - includeHidden: bool = None, - level: int = None, + checked: Optional[bool] = None, + disabled: Optional[bool] = None, + expanded: Optional[bool] = None, + includeHidden: Optional[bool] = None, + level: Optional[int] = None, name: Union[str, Pattern[str]] = None, - pressed: bool = None, - selected: bool = None, - exact: bool = None, + pressed: Optional[bool] = None, + selected: Optional[bool] = None, + exact: Optional[bool] = None, ) -> "Locator": return self.locator( get_by_role_selector( @@ -799,12 +813,12 @@ def get_by_test_id(self, testId: Union[str, Pattern[str]]) -> "Locator": return self.locator(get_by_test_id_selector(test_id_attribute_name(), testId)) def get_by_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_text_selector(text, exact=exact)) def get_by_title( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self.locator(get_by_title_selector(text, exact=exact)) @@ -848,30 +862,38 @@ def get_by_test_id_selector( def get_by_attribute_text_selector( - attr_name: str, text: Union[str, Pattern[str]], exact: bool = None + attr_name: str, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> str: return f"internal:attr=[{attr_name}={escape_for_attribute_selector(text, exact=exact)}]" -def get_by_label_selector(text: Union[str, Pattern[str]], exact: bool = None) -> str: +def get_by_label_selector( + text: Union[str, Pattern[str]], exact: Optional[bool] = None +) -> str: return "internal:label=" + escape_for_text_selector(text, exact=exact) -def get_by_alt_text_selector(text: Union[str, Pattern[str]], exact: bool = None) -> str: +def get_by_alt_text_selector( + text: Union[str, Pattern[str]], exact: Optional[bool] = None +) -> str: return get_by_attribute_text_selector("alt", text, exact=exact) -def get_by_title_selector(text: Union[str, Pattern[str]], exact: bool = None) -> str: +def get_by_title_selector( + text: Union[str, Pattern[str]], exact: Optional[bool] = None +) -> str: return get_by_attribute_text_selector("title", text, exact=exact) def get_by_placeholder_selector( - text: Union[str, Pattern[str]], exact: bool = None + text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> str: return get_by_attribute_text_selector("placeholder", text, exact=exact) -def get_by_text_selector(text: Union[str, Pattern[str]], exact: bool = None) -> str: +def get_by_text_selector( + text: Union[str, Pattern[str]], exact: Optional[bool] = None +) -> str: return "internal:text=" + escape_for_text_selector(text, exact=exact) @@ -881,15 +903,15 @@ def bool_to_js_bool(value: bool) -> str: def get_by_role_selector( role: AriaRole, - checked: bool = None, - disabled: bool = None, - expanded: bool = None, - includeHidden: bool = None, - level: int = None, + checked: Optional[bool] = None, + disabled: Optional[bool] = None, + expanded: Optional[bool] = None, + includeHidden: Optional[bool] = None, + level: Optional[int] = None, name: Union[str, Pattern[str]] = None, - pressed: bool = None, - selected: bool = None, - exact: bool = None, + pressed: Optional[bool] = None, + selected: Optional[bool] = None, + exact: Optional[bool] = None, ) -> str: props: List[Tuple[str, str]] = [] if checked is not None: diff --git a/playwright/_impl/_network.py b/playwright/_impl/_network.py index 03aa53588..886ce2b1b 100644 --- a/playwright/_impl/_network.py +++ b/playwright/_impl/_network.py @@ -301,7 +301,7 @@ def __repr__(self) -> str: def request(self) -> Request: return from_channel(self._initializer["request"]) - async def abort(self, errorCode: str = None) -> None: + async def abort(self, errorCode: Optional[str] = None) -> None: await self._handle_route( lambda: self._race_with_page_close( self._channel.send( @@ -316,12 +316,12 @@ async def abort(self, errorCode: str = None) -> None: async def fulfill( self, - status: int = None, + status: Optional[int] = None, headers: Dict[str, str] = None, body: Union[str, bytes] = None, - json: Any = None, + json: Optional[Any] = None, path: Union[str, Path] = None, - contentType: str = None, + contentType: Optional[str] = None, response: "APIResponse" = None, ) -> None: await self._handle_route( @@ -332,12 +332,12 @@ async def fulfill( async def _inner_fulfill( self, - status: int = None, + status: Optional[int] = None, headers: Dict[str, str] = None, body: Union[str, bytes] = None, - json: Any = None, + json: Optional[Any] = None, path: Union[str, Path] = None, - contentType: str = None, + contentType: Optional[str] = None, response: "APIResponse" = None, ) -> None: params = locals_to_params(locals()) @@ -406,12 +406,12 @@ async def _handle_route(self, callback: Callable) -> None: async def fetch( self, - url: str = None, - method: str = None, + url: Optional[str] = None, + method: Optional[str] = None, headers: Dict[str, str] = None, postData: Union[Any, str, bytes] = None, - maxRedirects: int = None, - timeout: float = None, + maxRedirects: Optional[int] = None, + timeout: Optional[float] = None, ) -> "APIResponse": return await self._connection.wrap_api_call( lambda: self._context.request._inner_fetch( @@ -427,8 +427,8 @@ async def fetch( async def fallback( self, - url: str = None, - method: str = None, + url: Optional[str] = None, + method: Optional[str] = None, headers: Dict[str, str] = None, postData: Union[Any, str, bytes] = None, ) -> None: @@ -439,8 +439,8 @@ async def fallback( async def continue_( self, - url: str = None, - method: str = None, + url: Optional[str] = None, + method: Optional[str] = None, headers: Dict[str, str] = None, postData: Union[Any, str, bytes] = None, ) -> None: @@ -662,8 +662,8 @@ def url(self) -> str: def expect_event( self, event: str, - predicate: Callable = None, - timeout: float = None, + predicate: Optional[Callable] = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl: if timeout is None: timeout = cast(Any, self._parent)._timeout_settings.timeout() @@ -683,7 +683,10 @@ def expect_event( return EventContextManagerImpl(waiter.result()) async def wait_for_event( - self, event: str, predicate: Callable = None, timeout: float = None + self, + event: str, + predicate: Optional[Callable] = None, + timeout: Optional[float] = None, ) -> Any: async with self.expect_event(event, predicate, timeout) as event_info: pass diff --git a/playwright/_impl/_page.py b/playwright/_impl/_page.py index ac6a55002..2ec860664 100644 --- a/playwright/_impl/_page.py +++ b/playwright/_impl/_page.py @@ -310,7 +310,9 @@ async def opener(self) -> Optional["Page"]: def main_frame(self) -> Frame: return self._main_frame - def frame(self, name: str = None, url: URLMatch = None) -> Optional[Frame]: + def frame( + self, name: Optional[str] = None, url: Optional[URLMatch] = None + ) -> Optional[Frame]: matcher = ( URLMatcher(self._browser_context._options.get("baseURL"), url) if url @@ -340,7 +342,7 @@ def set_default_timeout(self, timeout: float) -> None: async def query_selector( self, selector: str, - strict: bool = None, + strict: Optional[bool] = None, ) -> Optional[ElementHandle]: return await self._main_frame.query_selector(selector, strict) @@ -350,39 +352,57 @@ async def query_selector_all(self, selector: str) -> List[ElementHandle]: async def wait_for_selector( self, selector: str, - timeout: float = None, + timeout: Optional[float] = None, state: Literal["attached", "detached", "hidden", "visible"] = None, - strict: bool = None, + strict: Optional[bool] = None, ) -> Optional[ElementHandle]: return await self._main_frame.wait_for_selector(**locals_to_params(locals())) async def is_checked( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._main_frame.is_checked(**locals_to_params(locals())) async def is_disabled( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._main_frame.is_disabled(**locals_to_params(locals())) async def is_editable( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._main_frame.is_editable(**locals_to_params(locals())) async def is_enabled( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._main_frame.is_enabled(**locals_to_params(locals())) async def is_hidden( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._main_frame.is_hidden(**locals_to_params(locals())) async def is_visible( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> bool: return await self._main_frame.is_visible(**locals_to_params(locals())) @@ -390,17 +410,19 @@ async def dispatch_event( self, selector: str, type: str, - eventInit: Dict = None, - timeout: float = None, - strict: bool = None, + eventInit: Optional[Dict] = None, + timeout: Optional[float] = None, + strict: Optional[bool] = None, ) -> None: return await self._main_frame.dispatch_event(**locals_to_params(locals())) - async def evaluate(self, expression: str, arg: Serializable = None) -> Any: + async def evaluate( + self, expression: str, arg: Optional[Serializable] = None + ) -> Any: return await self._main_frame.evaluate(expression, arg) async def evaluate_handle( - self, expression: str, arg: Serializable = None + self, expression: str, arg: Optional[Serializable] = None ) -> JSHandle: return await self._main_frame.evaluate_handle(expression, arg) @@ -408,8 +430,8 @@ async def eval_on_selector( self, selector: str, expression: str, - arg: Serializable = None, - strict: bool = None, + arg: Optional[Serializable] = None, + strict: Optional[bool] = None, ) -> Any: return await self._main_frame.eval_on_selector( selector, expression, arg, strict @@ -419,21 +441,24 @@ async def eval_on_selector_all( self, selector: str, expression: str, - arg: Serializable = None, + arg: Optional[Serializable] = None, ) -> Any: return await self._main_frame.eval_on_selector_all(selector, expression, arg) async def add_script_tag( self, - url: str = None, + url: Optional[str] = None, path: Union[str, Path] = None, - content: str = None, - type: str = None, + content: Optional[str] = None, + type: Optional[str] = None, ) -> ElementHandle: return await self._main_frame.add_script_tag(**locals_to_params(locals())) async def add_style_tag( - self, url: str = None, path: Union[str, Path] = None, content: str = None + self, + url: Optional[str] = None, + path: Union[str, Path] = None, + content: Optional[str] = None, ) -> ElementHandle: return await self._main_frame.add_style_tag(**locals_to_params(locals())) @@ -441,7 +466,7 @@ async def expose_function(self, name: str, callback: Callable) -> None: await self.expose_binding(name, lambda source, *args: callback(*args)) async def expose_binding( - self, name: str, callback: Callable, handle: bool = None + self, name: str, callback: Callable, handle: Optional[bool] = None ) -> None: if name in self._bindings: raise Error(f'Function "{name}" has been already registered') @@ -469,24 +494,24 @@ async def content(self) -> str: async def set_content( self, html: str, - timeout: float = None, - waitUntil: DocumentLoadState = None, + timeout: Optional[float] = None, + waitUntil: Optional[DocumentLoadState] = None, ) -> None: return await self._main_frame.set_content(**locals_to_params(locals())) async def goto( self, url: str, - timeout: float = None, - waitUntil: DocumentLoadState = None, - referer: str = None, + timeout: Optional[float] = None, + waitUntil: Optional[DocumentLoadState] = None, + referer: Optional[str] = None, ) -> Optional[Response]: return await self._main_frame.goto(**locals_to_params(locals())) async def reload( self, - timeout: float = None, - waitUntil: DocumentLoadState = None, + timeout: Optional[float] = None, + waitUntil: Optional[DocumentLoadState] = None, ) -> Optional[Response]: return from_nullable_channel( await self._channel.send("reload", locals_to_params(locals())) @@ -495,20 +520,23 @@ async def reload( async def wait_for_load_state( self, state: Literal["domcontentloaded", "load", "networkidle"] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> None: return await self._main_frame.wait_for_load_state(**locals_to_params(locals())) async def wait_for_url( self, url: URLMatch, - waitUntil: DocumentLoadState = None, - timeout: float = None, + waitUntil: Optional[DocumentLoadState] = None, + timeout: Optional[float] = None, ) -> None: return await self._main_frame.wait_for_url(**locals_to_params(locals())) async def wait_for_event( - self, event: str, predicate: Callable = None, timeout: float = None + self, + event: str, + predicate: Optional[Callable] = None, + timeout: Optional[float] = None, ) -> Any: async with self.expect_event(event, predicate, timeout) as event_info: pass @@ -516,8 +544,8 @@ async def wait_for_event( async def go_back( self, - timeout: float = None, - waitUntil: DocumentLoadState = None, + timeout: Optional[float] = None, + waitUntil: Optional[DocumentLoadState] = None, ) -> Optional[Response]: return from_nullable_channel( await self._channel.send("goBack", locals_to_params(locals())) @@ -525,8 +553,8 @@ async def go_back( async def go_forward( self, - timeout: float = None, - waitUntil: DocumentLoadState = None, + timeout: Optional[float] = None, + waitUntil: Optional[DocumentLoadState] = None, ) -> Optional[Response]: return from_nullable_channel( await self._channel.send("goForward", locals_to_params(locals())) @@ -535,9 +563,9 @@ async def go_forward( async def emulate_media( self, media: Literal["null", "print", "screen"] = None, - colorScheme: ColorScheme = None, - reducedMotion: ReducedMotion = None, - forcedColors: ForcedColors = None, + colorScheme: Optional[ColorScheme] = None, + reducedMotion: Optional[ReducedMotion] = None, + forcedColors: Optional[ForcedColors] = None, ) -> None: params = locals_to_params(locals()) if "media" in params: @@ -568,7 +596,7 @@ async def bring_to_front(self) -> None: await self._channel.send("bringToFront") async def add_init_script( - self, script: str = None, path: Union[str, Path] = None + self, script: Optional[str] = None, path: Union[str, Path] = None ) -> None: if path: script = (await async_readfile(path)).decode() @@ -577,7 +605,7 @@ async def add_init_script( await self._channel.send("addInitScript", dict(source=script)) async def route( - self, url: URLMatch, handler: RouteHandlerCallback, times: int = None + self, url: URLMatch, handler: RouteHandlerCallback, times: Optional[int] = None ) -> None: self._routes.insert( 0, @@ -634,10 +662,10 @@ async def route_from_har( self, har: Union[Path, str], url: Union[Pattern[str], str] = None, - notFound: RouteFromHarNotFoundPolicy = None, - update: bool = None, + notFound: Optional[RouteFromHarNotFoundPolicy] = None, + update: Optional[bool] = None, updateContent: Literal["attach", "embed"] = None, - updateMode: HarMode = None, + updateMode: Optional[HarMode] = None, ) -> None: if update: await self._browser_context._record_into_har( @@ -665,19 +693,19 @@ async def _update_interception_patterns(self) -> None: async def screenshot( self, - timeout: float = None, + timeout: Optional[float] = None, type: Literal["jpeg", "png"] = None, path: Union[str, Path] = None, - quality: int = None, - omitBackground: bool = None, - fullPage: bool = None, - clip: FloatRect = None, + quality: Optional[int] = None, + omitBackground: Optional[bool] = None, + fullPage: Optional[bool] = None, + clip: Optional[FloatRect] = None, animations: Literal["allow", "disabled"] = None, caret: Literal["hide", "initial"] = None, scale: Literal["css", "device"] = None, mask: Sequence["Locator"] = None, - maskColor: str = None, - style: str = None, + maskColor: Optional[str] = None, + style: Optional[str] = None, ) -> bytes: params = locals_to_params(locals()) if "path" in params: @@ -704,7 +732,9 @@ async def screenshot( async def title(self) -> str: return await self._main_frame.title() - async def close(self, runBeforeUnload: bool = None, reason: str = None) -> None: + async def close( + self, runBeforeUnload: Optional[bool] = None, reason: Optional[str] = None + ) -> None: self._close_reason = reason self._close_was_called = True try: @@ -722,15 +752,15 @@ async def click( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - clickCount: int = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - trial: bool = None, - strict: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + clickCount: Optional[int] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + trial: Optional[bool] = None, + strict: Optional[bool] = None, ) -> None: return await self._main_frame.click(**locals_to_params(locals())) @@ -738,14 +768,14 @@ async def dblclick( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - delay: float = None, - button: MouseButton = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + delay: Optional[float] = None, + button: Optional[MouseButton] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: return await self._main_frame.dblclick(**locals_to_params(locals())) @@ -753,12 +783,12 @@ async def tap( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: return await self._main_frame.tap(**locals_to_params(locals())) @@ -766,10 +796,10 @@ async def fill( self, selector: str, value: str, - timeout: float = None, - noWaitAfter: bool = None, - strict: bool = None, - force: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + force: Optional[bool] = None, ) -> None: return await self._main_frame.fill(**locals_to_params(locals())) @@ -790,32 +820,32 @@ def locator( ) def get_by_alt_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self._main_frame.get_by_alt_text(text, exact=exact) def get_by_label( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self._main_frame.get_by_label(text, exact=exact) def get_by_placeholder( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self._main_frame.get_by_placeholder(text, exact=exact) def get_by_role( self, role: AriaRole, - checked: bool = None, - disabled: bool = None, - expanded: bool = None, - includeHidden: bool = None, - level: int = None, + checked: Optional[bool] = None, + disabled: Optional[bool] = None, + expanded: Optional[bool] = None, + includeHidden: Optional[bool] = None, + level: Optional[int] = None, name: Union[str, Pattern[str]] = None, - pressed: bool = None, - selected: bool = None, - exact: bool = None, + pressed: Optional[bool] = None, + selected: Optional[bool] = None, + exact: Optional[bool] = None, ) -> "Locator": return self._main_frame.get_by_role( role, @@ -834,12 +864,12 @@ def get_by_test_id(self, testId: Union[str, Pattern[str]]) -> "Locator": return self._main_frame.get_by_test_id(testId) def get_by_text( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self._main_frame.get_by_text(text, exact=exact) def get_by_title( - self, text: Union[str, Pattern[str]], exact: bool = None + self, text: Union[str, Pattern[str]], exact: Optional[bool] = None ) -> "Locator": return self._main_frame.get_by_title(text, exact=exact) @@ -847,27 +877,43 @@ def frame_locator(self, selector: str) -> "FrameLocator": return self.main_frame.frame_locator(selector) async def focus( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> None: return await self._main_frame.focus(**locals_to_params(locals())) async def text_content( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> Optional[str]: return await self._main_frame.text_content(**locals_to_params(locals())) async def inner_text( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> str: return await self._main_frame.inner_text(**locals_to_params(locals())) async def inner_html( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> str: return await self._main_frame.inner_html(**locals_to_params(locals())) async def get_attribute( - self, selector: str, name: str, strict: bool = None, timeout: float = None + self, + selector: str, + name: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> Optional[str]: return await self._main_frame.get_attribute(**locals_to_params(locals())) @@ -875,12 +921,12 @@ async def hover( self, selector: str, modifiers: Sequence[KeyboardModifier] = None, - position: Position = None, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: return await self._main_frame.hover(**locals_to_params(locals())) @@ -888,13 +934,13 @@ async def drag_and_drop( self, source: str, target: str, - sourcePosition: Position = None, - targetPosition: Position = None, - force: bool = None, - noWaitAfter: bool = None, - timeout: float = None, - strict: bool = None, - trial: bool = None, + sourcePosition: Optional[Position] = None, + targetPosition: Optional[Position] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + timeout: Optional[float] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: return await self._main_frame.drag_and_drop(**locals_to_params(locals())) @@ -905,16 +951,19 @@ async def select_option( index: Union[int, Sequence[int]] = None, label: Union[str, Sequence[str]] = None, element: Union["ElementHandle", Sequence["ElementHandle"]] = None, - timeout: float = None, - noWaitAfter: bool = None, - force: bool = None, - strict: bool = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + force: Optional[bool] = None, + strict: Optional[bool] = None, ) -> List[str]: params = locals_to_params(locals()) return await self._main_frame.select_option(**params) async def input_value( - self, selector: str, strict: bool = None, timeout: float = None + self, + selector: str, + strict: Optional[bool] = None, + timeout: Optional[float] = None, ) -> str: params = locals_to_params(locals()) return await self._main_frame.input_value(**params) @@ -925,9 +974,9 @@ async def set_input_files( files: Union[ str, Path, FilePayload, Sequence[Union[str, Path]], Sequence[FilePayload] ], - timeout: float = None, - strict: bool = None, - noWaitAfter: bool = None, + timeout: Optional[float] = None, + strict: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, ) -> None: return await self._main_frame.set_input_files(**locals_to_params(locals())) @@ -935,10 +984,10 @@ async def type( self, selector: str, text: str, - delay: float = None, - timeout: float = None, - noWaitAfter: bool = None, - strict: bool = None, + delay: Optional[float] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, ) -> None: return await self._main_frame.type(**locals_to_params(locals())) @@ -946,34 +995,34 @@ async def press( self, selector: str, key: str, - delay: float = None, - timeout: float = None, - noWaitAfter: bool = None, - strict: bool = None, + delay: Optional[float] = None, + timeout: Optional[float] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, ) -> None: return await self._main_frame.press(**locals_to_params(locals())) async def check( self, selector: str, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: return await self._main_frame.check(**locals_to_params(locals())) async def uncheck( self, selector: str, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: return await self._main_frame.uncheck(**locals_to_params(locals())) @@ -983,8 +1032,8 @@ async def wait_for_timeout(self, timeout: float) -> None: async def wait_for_function( self, expression: str, - arg: Serializable = None, - timeout: float = None, + arg: Optional[Serializable] = None, + timeout: Optional[float] = None, polling: Union[float, Literal["raf"]] = None, ) -> JSHandle: return await self._main_frame.wait_for_function(**locals_to_params(locals())) @@ -1020,18 +1069,18 @@ async def pause(self) -> None: async def pdf( self, - scale: float = None, - displayHeaderFooter: bool = None, - headerTemplate: str = None, - footerTemplate: str = None, - printBackground: bool = None, - landscape: bool = None, - pageRanges: str = None, - format: str = None, + scale: Optional[float] = None, + displayHeaderFooter: Optional[bool] = None, + headerTemplate: Optional[str] = None, + footerTemplate: Optional[str] = None, + printBackground: Optional[bool] = None, + landscape: Optional[bool] = None, + pageRanges: Optional[str] = None, + format: Optional[str] = None, width: Union[str, float] = None, height: Union[str, float] = None, - preferCSSPageSize: bool = None, - margin: PdfMargins = None, + preferCSSPageSize: Optional[bool] = None, + margin: Optional[PdfMargins] = None, path: Union[str, Path] = None, ) -> bytes: params = locals_to_params(locals()) @@ -1060,8 +1109,8 @@ def _close_error_with_reason(self) -> TargetClosedError: def expect_event( self, event: str, - predicate: Callable = None, - timeout: float = None, + predicate: Optional[Callable] = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl: return self._expect_event( event, predicate, timeout, f'waiting for event "{event}"' @@ -1070,9 +1119,9 @@ def expect_event( def _expect_event( self, event: str, - predicate: Callable = None, - timeout: float = None, - log_line: str = None, + predicate: Optional[Callable] = None, + timeout: Optional[float] = None, + log_line: Optional[str] = None, ) -> EventContextManagerImpl: if timeout is None: timeout = self._timeout_settings.timeout() @@ -1094,43 +1143,43 @@ def _expect_event( def expect_console_message( self, predicate: Callable[[ConsoleMessage], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[ConsoleMessage]: return self.expect_event(Page.Events.Console, predicate, timeout) def expect_download( self, predicate: Callable[[Download], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[Download]: return self.expect_event(Page.Events.Download, predicate, timeout) def expect_file_chooser( self, predicate: Callable[[FileChooser], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[FileChooser]: return self.expect_event(Page.Events.FileChooser, predicate, timeout) def expect_navigation( self, - url: URLMatch = None, - waitUntil: DocumentLoadState = None, - timeout: float = None, + url: Optional[URLMatch] = None, + waitUntil: Optional[DocumentLoadState] = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[Response]: return self.main_frame.expect_navigation(url, waitUntil, timeout) def expect_popup( self, predicate: Callable[["Page"], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl["Page"]: return self.expect_event(Page.Events.Popup, predicate, timeout) def expect_request( self, urlOrPredicate: URLMatchRequest, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[Request]: matcher = ( None @@ -1160,7 +1209,7 @@ def my_predicate(request: Request) -> bool: def expect_request_finished( self, predicate: Callable[["Request"], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[Request]: return self.expect_event( Page.Events.RequestFinished, predicate=predicate, timeout=timeout @@ -1169,7 +1218,7 @@ def expect_request_finished( def expect_response( self, urlOrPredicate: URLMatchResponse, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl[Response]: matcher = ( None @@ -1199,14 +1248,14 @@ def my_predicate(response: Response) -> bool: def expect_websocket( self, predicate: Callable[["WebSocket"], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl["WebSocket"]: return self.expect_event("websocket", predicate, timeout) def expect_worker( self, predicate: Callable[["Worker"], bool] = None, - timeout: float = None, + timeout: Optional[float] = None, ) -> EventContextManagerImpl["Worker"]: return self.expect_event("worker", predicate, timeout) @@ -1214,12 +1263,12 @@ async def set_checked( self, selector: str, checked: bool, - position: Position = None, - timeout: float = None, - force: bool = None, - noWaitAfter: bool = None, - strict: bool = None, - trial: bool = None, + position: Optional[Position] = None, + timeout: Optional[float] = None, + force: Optional[bool] = None, + noWaitAfter: Optional[bool] = None, + strict: Optional[bool] = None, + trial: Optional[bool] = None, ) -> None: if checked: await self.check( @@ -1268,7 +1317,9 @@ def _on_close(self) -> None: def url(self) -> str: return self._initializer["url"] - async def evaluate(self, expression: str, arg: Serializable = None) -> Any: + async def evaluate( + self, expression: str, arg: Optional[Serializable] = None + ) -> Any: return parse_result( await self._channel.send( "evaluateExpression", @@ -1280,7 +1331,7 @@ async def evaluate(self, expression: str, arg: Serializable = None) -> Any: ) async def evaluate_handle( - self, expression: str, arg: Serializable = None + self, expression: str, arg: Optional[Serializable] = None ) -> JSHandle: return from_channel( await self._channel.send( diff --git a/playwright/_impl/_selectors.py b/playwright/_impl/_selectors.py index cf8af8c06..7d3697f23 100644 --- a/playwright/_impl/_selectors.py +++ b/playwright/_impl/_selectors.py @@ -14,7 +14,7 @@ import asyncio from pathlib import Path -from typing import Any, Dict, List, Set, Union +from typing import Any, Dict, List, Optional, Set, Union from playwright._impl._connection import ChannelOwner from playwright._impl._errors import Error @@ -32,9 +32,9 @@ def __init__(self, loop: asyncio.AbstractEventLoop, dispatcher_fiber: Any) -> No async def register( self, name: str, - script: str = None, + script: Optional[str] = None, path: Union[str, Path] = None, - contentScript: bool = None, + contentScript: Optional[bool] = None, ) -> None: if not script and not path: raise Error("Either source or path should be specified") diff --git a/playwright/_impl/_str_utils.py b/playwright/_impl/_str_utils.py index 8b3e65a39..16cdd9861 100644 --- a/playwright/_impl/_str_utils.py +++ b/playwright/_impl/_str_utils.py @@ -14,7 +14,7 @@ import json import re -from typing import Pattern, Union +from typing import Optional, Pattern, Union def escape_regex_flags(pattern: Pattern) -> str: @@ -52,7 +52,9 @@ def escape_regex_for_selector(text: Pattern) -> str: def escape_for_text_selector( - text: Union[str, Pattern[str]], exact: bool = None, case_sensitive: bool = None + text: Union[str, Pattern[str]], + exact: Optional[bool] = None, + case_sensitive: Optional[bool] = None, ) -> str: if isinstance(text, Pattern): return escape_regex_for_selector(text) @@ -60,7 +62,7 @@ def escape_for_text_selector( def escape_for_attribute_selector( - value: Union[str, Pattern], exact: bool = None + value: Union[str, Pattern], exact: Optional[bool] = None ) -> str: if isinstance(value, Pattern): return escape_regex_for_selector(value) diff --git a/playwright/_impl/_tracing.py b/playwright/_impl/_tracing.py index 7f7972372..687749f14 100644 --- a/playwright/_impl/_tracing.py +++ b/playwright/_impl/_tracing.py @@ -32,11 +32,11 @@ def __init__( async def start( self, - name: str = None, - title: str = None, - snapshots: bool = None, - screenshots: bool = None, - sources: bool = None, + name: Optional[str] = None, + title: Optional[str] = None, + snapshots: Optional[bool] = None, + screenshots: Optional[bool] = None, + sources: Optional[bool] = None, ) -> None: params = locals_to_params(locals()) self._include_sources = bool(sources) @@ -50,7 +50,9 @@ async def _inner_start() -> str: trace_name = await self._connection.wrap_api_call(_inner_start, True) await self._start_collecting_stacks(trace_name) - async def start_chunk(self, title: str = None, name: str = None) -> None: + async def start_chunk( + self, title: Optional[str] = None, name: Optional[str] = None + ) -> None: params = locals_to_params(locals()) trace_name = await self._channel.send("tracingStartChunk", params) await self._start_collecting_stacks(trace_name) diff --git a/playwright/_impl/_waiter.py b/playwright/_impl/_waiter.py index 7b0ad2cc6..ae6d01f44 100644 --- a/playwright/_impl/_waiter.py +++ b/playwright/_impl/_waiter.py @@ -16,7 +16,7 @@ import math import uuid from asyncio.tasks import Task -from typing import Any, Callable, List, Tuple, Union +from typing import Any, Callable, List, Optional, Tuple, Union from pyee import EventEmitter @@ -47,7 +47,9 @@ def _wait_for_event_info_before(self, wait_id: str, event: str) -> None: }, ) - def _wait_for_event_info_after(self, wait_id: str, error: Exception = None) -> None: + def _wait_for_event_info_after( + self, wait_id: str, error: Optional[Exception] = None + ) -> None: self._channel._connection.wrap_api_call_sync( lambda: self._channel.send_no_reply( "waitForEventInfo", @@ -67,9 +69,9 @@ def reject_on_event( emitter: EventEmitter, event: str, error: Union[Error, Callable[..., Error]], - predicate: Callable = None, + predicate: Optional[Callable] = None, ) -> None: - def listener(event_data: Any = None) -> None: + def listener(event_data: Optional[Any] = None) -> None: if not predicate or predicate(event_data): self._reject(error() if callable(error) else error) @@ -112,9 +114,9 @@ def wait_for_event( self, emitter: EventEmitter, event: str, - predicate: Callable = None, + predicate: Optional[Callable] = None, ) -> None: - def listener(event_data: Any = None) -> None: + def listener(event_data: Optional[Any] = None) -> None: if not predicate or predicate(event_data): self._fulfill(event_data) From 4af99513cdde092ac96627ee72a3e39816345c67 Mon Sep 17 00:00:00 2001 From: danphenderson Date: Thu, 15 Feb 2024 17:55:19 -0800 Subject: [PATCH 2/9] chore(wip): update Union[Type, None] to Optional[Type] Changes where automated with this perl one-liner: `perl -pi -e 's/Union\[\s*(\w+)\s*,\s*None\s*\]/Optional[$1]/g' \ $(find . -type f -name '*.py')` WIP, still need to address the case where the union specifies more than two different types. issue: 2303 --- playwright/_impl/_helper.py | 2 +- playwright/async_api/_generated.py | 1496 ++++++++++++++-------------- playwright/sync_api/_generated.py | 1496 ++++++++++++++-------------- 3 files changed, 1497 insertions(+), 1497 deletions(-) diff --git a/playwright/_impl/_helper.py b/playwright/_impl/_helper.py index 1cf2e0897..7f35905ea 100644 --- a/playwright/_impl/_helper.py +++ b/playwright/_impl/_helper.py @@ -142,7 +142,7 @@ class FrameNavigatedEvent(TypedDict): class URLMatcher: - def __init__(self, base_url: Union[str, None], match: URLMatch) -> None: + def __init__(self, base_url: Optional[str], match: URLMatch) -> None: self._callback: Optional[Callable[[str], bool]] = None self._regex_obj: Optional[Pattern[str]] = None if isinstance(match, str): diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py index 831d8dcfb..f0413e7ad 100644 --- a/playwright/async_api/_generated.py +++ b/playwright/async_api/_generated.py @@ -133,7 +133,7 @@ def post_data(self) -> typing.Optional[str]: Returns ------- - Union[str, None] + Optional[str] """ return mapping.from_maybe_impl(self._impl_obj.post_data) @@ -148,7 +148,7 @@ def post_data_json(self) -> typing.Optional[typing.Any]: Returns ------- - Union[Any, None] + Optional[Any] """ return mapping.from_maybe_impl(self._impl_obj.post_data_json) @@ -160,7 +160,7 @@ def post_data_buffer(self) -> typing.Optional[bytes]: Returns ------- - Union[bytes, None] + Optional[bytes] """ return mapping.from_maybe_impl(self._impl_obj.post_data_buffer) @@ -219,7 +219,7 @@ def redirected_from(self) -> typing.Optional["Request"]: Returns ------- - Union[Request, None] + Optional[Request] """ return mapping.from_impl_nullable(self._impl_obj.redirected_from) @@ -239,7 +239,7 @@ def redirected_to(self) -> typing.Optional["Request"]: Returns ------- - Union[Request, None] + Optional[Request] """ return mapping.from_impl_nullable(self._impl_obj.redirected_to) @@ -259,7 +259,7 @@ def failure(self) -> typing.Optional[str]: Returns ------- - Union[str, None] + Optional[str] """ return mapping.from_maybe_impl(self._impl_obj.failure) @@ -319,7 +319,7 @@ async def response(self) -> typing.Optional["Response"]: Returns ------- - Union[Response, None] + Optional[Response] """ return mapping.from_impl_nullable(await self._impl_obj.response()) @@ -377,7 +377,7 @@ async def header_value(self, name: str) -> typing.Optional[str]: Returns ------- - Union[str, None] + Optional[str] """ return mapping.from_maybe_impl(await self._impl_obj.header_value(name=name)) @@ -526,7 +526,7 @@ async def header_value(self, name: str) -> typing.Optional[str]: Returns ------- - Union[str, None] + Optional[str] """ return mapping.from_maybe_impl(await self._impl_obj.header_value(name=name)) @@ -567,7 +567,7 @@ async def security_details(self) -> typing.Optional[SecurityDetails]: Returns ------- - Union[{issuer: Union[str, None], protocol: Union[str, None], subjectName: Union[str, None], validFrom: Union[float, None], validTo: Union[float, None]}, None] + Union[{issuer: Optional[str], protocol: Optional[str], subjectName: Optional[str], validFrom: Optional[float], validTo: Optional[float]}, None] """ return mapping.from_impl_nullable(await self._impl_obj.security_details()) @@ -642,7 +642,7 @@ async def abort(self, error_code: typing.Optional[str] = None) -> None: Parameters ---------- - error_code : Union[str, None] + error_code : Optional[str] Optional error code. Defaults to `failed`, could be one of the following: - `'aborted'` - An operation was aborted (due to user action) - `'accessdenied'` - Permission to access a resource, other than the network, was denied @@ -698,20 +698,20 @@ async def fulfill( Parameters ---------- - status : Union[int, None] + status : Optional[int] Response status code, defaults to `200`. headers : Union[Dict[str, str], None] Response headers. Header values will be converted to a string. body : Union[bytes, str, None] Response body. - json : Union[Any, None] + json : Optional[Any] JSON response. This method will set the content type to `application/json` if not set. path : Union[pathlib.Path, str, None] File path to respond with. The content type will be inferred from file extension. If `path` is a relative path, then it is resolved relative to the current working directory. - content_type : Union[str, None] + content_type : Optional[str] If set, equals to setting `Content-Type` response header. - response : Union[APIResponse, None] + response : Optional[APIResponse] `APIResponse` to fulfill route's request with. Individual fields of the response (such as headers) can be overridden using fulfill options. """ @@ -763,9 +763,9 @@ async def handle(route): Parameters ---------- - url : Union[str, None] + url : Optional[str] If set changes the request URL. New URL must have same protocol as original one. - method : Union[str, None] + method : Optional[str] If set changes the request method (e.g. GET or POST). headers : Union[Dict[str, str], None] If set changes the request HTTP headers. Header values will be converted to a string. @@ -773,10 +773,10 @@ async def handle(route): Allows to set post data of the request. If the data parameter is an object, it will be serialized to json string and `content-type` header will be set to `application/json` if not explicitly set. Otherwise the `content-type` header will be set to `application/octet-stream` if not explicitly set. - max_redirects : Union[int, None] + max_redirects : Optional[int] Maximum number of request redirects that will be followed automatically. An error will be thrown if the number is exceeded. Defaults to `20`. Pass `0` to not follow redirects. - timeout : Union[float, None] + timeout : Optional[float] Request timeout in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. Returns @@ -860,10 +860,10 @@ async def handle(route, request): Parameters ---------- - url : Union[str, None] + url : Optional[str] If set changes the request URL. New URL must have same protocol as original one. Changing the URL won't affect the route matching, all the routes are matched using the original request URL. - method : Union[str, None] + method : Optional[str] If set changes the request method (e.g. GET or POST). headers : Union[Dict[str, str], None] If set changes the request HTTP headers. Header values will be converted to a string. @@ -915,9 +915,9 @@ async def handle(route, request): Parameters ---------- - url : Union[str, None] + url : Optional[str] If set changes the request URL. New URL must have same protocol as original one. - method : Union[str, None] + method : Optional[str] If set changes the request method (e.g. GET or POST). headers : Union[Dict[str, str], None] If set changes the request HTTP headers. Header values will be converted to a string. @@ -1061,9 +1061,9 @@ def expect_event( ---------- event : str Event name, same one would pass into `webSocket.on(event)`. - predicate : Union[Callable, None] + predicate : Optional[Callable] Receives the event data and resolves to truthy value when the waiting should resolve. - timeout : Union[float, None] + timeout : Optional[float] Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -1097,9 +1097,9 @@ async def wait_for_event( ---------- event : str Event name, same one typically passed into `*.on(event)`. - predicate : Union[Callable, None] + predicate : Optional[Callable] Receives the event data and resolves to truthy value when the waiting should resolve. - timeout : Union[float, None] + timeout : Optional[float] Maximum time to wait for in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()`. @@ -1229,7 +1229,7 @@ async def type(self, text: str, *, delay: typing.Optional[float] = None) -> None ---------- text : str A text to type into a focused element. - delay : Union[float, None] + delay : Optional[float] Time to wait between key presses in milliseconds. Defaults to 0. """ @@ -1281,7 +1281,7 @@ async def press(self, key: str, *, delay: typing.Optional[float] = None) -> None ---------- key : str Name of the key to press or a character to generate, such as `ArrowLeft` or `a`. - delay : Union[float, None] + delay : Optional[float] Time to wait between `keydown` and `keyup` in milliseconds. Defaults to 0. """ @@ -1303,7 +1303,7 @@ async def move( ---------- x : float y : float - steps : Union[int, None] + steps : Optional[int] Defaults to 1. Sends intermediate `mousemove` events. """ @@ -1323,7 +1323,7 @@ async def down( ---------- button : Union["left", "middle", "right", None] Defaults to `left`. - click_count : Union[int, None] + click_count : Optional[int] defaults to 1. See [UIEvent.detail]. """ @@ -1345,7 +1345,7 @@ async def up( ---------- button : Union["left", "middle", "right", None] Defaults to `left`. - click_count : Union[int, None] + click_count : Optional[int] defaults to 1. See [UIEvent.detail]. """ @@ -1370,11 +1370,11 @@ async def click( ---------- x : float y : float - delay : Union[float, None] + delay : Optional[float] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. button : Union["left", "middle", "right", None] Defaults to `left`. - click_count : Union[int, None] + click_count : Optional[int] defaults to 1. See [UIEvent.detail]. """ @@ -1401,7 +1401,7 @@ async def dblclick( ---------- x : float y : float - delay : Union[float, None] + delay : Optional[float] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. button : Union["left", "middle", "right", None] Defaults to `left`. @@ -1480,7 +1480,7 @@ async def evaluate( expression : str JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked. - arg : Union[Any, None] + arg : Optional[Any] Optional argument to pass to `expression`. Returns @@ -1516,7 +1516,7 @@ async def evaluate_handle( expression : str JavaScript expression to be evaluated in the browser context. If the expression evaluates to a function, the function is automatically invoked. - arg : Union[Any, None] + arg : Optional[Any] Optional argument to pass to `expression`. Returns @@ -1578,7 +1578,7 @@ def as_element(self) -> typing.Optional["ElementHandle"]: Returns ------- - Union[ElementHandle, None] + Optional[ElementHandle] """ return mapping.from_impl_nullable(self._impl_obj.as_element()) @@ -1618,7 +1618,7 @@ def as_element(self) -> typing.Optional["ElementHandle"]: Returns ------- - Union[ElementHandle, None] + Optional[ElementHandle] """ return mapping.from_impl_nullable(self._impl_obj.as_element()) @@ -1630,7 +1630,7 @@ async def owner_frame(self) -> typing.Optional["Frame"]: Returns ------- - Union[Frame, None] + Optional[Frame] """ return mapping.from_impl_nullable(await self._impl_obj.owner_frame()) @@ -1642,7 +1642,7 @@ async def content_frame(self) -> typing.Optional["Frame"]: Returns ------- - Union[Frame, None] + Optional[Frame] """ return mapping.from_impl_nullable(await self._impl_obj.content_frame()) @@ -1659,7 +1659,7 @@ async def get_attribute(self, name: str) -> typing.Optional[str]: Returns ------- - Union[str, None] + Optional[str] """ return mapping.from_maybe_impl(await self._impl_obj.get_attribute(name=name)) @@ -1671,7 +1671,7 @@ async def text_content(self) -> typing.Optional[str]: Returns ------- - Union[str, None] + Optional[str] """ return mapping.from_maybe_impl(await self._impl_obj.text_content()) @@ -1814,7 +1814,7 @@ async def dispatch_event( ---------- type : str DOM event type: `"click"`, `"dragstart"`, etc. - event_init : Union[Dict, None] + event_init : Optional[Dict] Optional event-specific initialization properties. """ @@ -1838,7 +1838,7 @@ async def scroll_into_view_if_needed( Parameters ---------- - timeout : Union[float, None] + timeout : Optional[float] Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. """ @@ -1880,16 +1880,16 @@ async def hover( position : Union[{x: float, y: float}, None] A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. - timeout : Union[float, None] + timeout : Optional[float] Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. - no_wait_after : Union[bool, None] + no_wait_after : Optional[bool] Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`. - force : Union[bool, None] + force : Optional[bool] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. - trial : Union[bool, None] + trial : Optional[bool] When set, this method only performs the [actionability](../actionability.md) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. """ @@ -1941,22 +1941,22 @@ async def click( position : Union[{x: float, y: float}, None] A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. - delay : Union[float, None] + delay : Optional[float] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. button : Union["left", "middle", "right", None] Defaults to `left`. - click_count : Union[int, None] + click_count : Optional[int] defaults to 1. See [UIEvent.detail]. - timeout : Union[float, None] + timeout : Optional[float] Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. - force : Union[bool, None] + force : Optional[bool] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. - no_wait_after : Union[bool, None] + no_wait_after : Optional[bool] Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`. - trial : Union[bool, None] + trial : Optional[bool] When set, this method only performs the [actionability](../actionability.md) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. """ @@ -2013,20 +2013,20 @@ async def dblclick( position : Union[{x: float, y: float}, None] A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. - delay : Union[float, None] + delay : Optional[float] Time to wait between `mousedown` and `mouseup` in milliseconds. Defaults to 0. button : Union["left", "middle", "right", None] Defaults to `left`. - timeout : Union[float, None] + timeout : Optional[float] Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. - force : Union[bool, None] + force : Optional[bool] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. - no_wait_after : Union[bool, None] + no_wait_after : Optional[bool] Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`. - trial : Union[bool, None] + trial : Optional[bool] When set, this method only performs the [actionability](../actionability.md) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. """ @@ -2094,12 +2094,12 @@ async def select_option( otherwise only the first option matching one of the passed options is selected. Optional. element : Union[ElementHandle, Sequence[ElementHandle], None] Option elements to select. Optional. - timeout : Union[float, None] + timeout : Optional[float] Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. - force : Union[bool, None] + force : Optional[bool] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. - no_wait_after : Union[bool, None] + no_wait_after : Optional[bool] Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`. @@ -2156,16 +2156,16 @@ async def tap( position : Union[{x: float, y: float}, None] A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element. - timeout : Union[float, None] + timeout : Optional[float] Maximum time in milliseconds. Defaults to `30000` (30 seconds). Pass `0` to disable timeout. The default value can be changed by using the `browser_context.set_default_timeout()` or `page.set_default_timeout()` methods. - force : Union[bool, None] + force : Optional[bool] Whether to bypass the [actionability](../actionability.md) checks. Defaults to `false`. - no_wait_after : Union[bool, None] + no_wait_after : Optional[bool] Actions that initiate navigations are waiting for these navigations to happen and for pages to start loading. You can opt out of waiting via setting this flag. You would only need this option in the exceptional cases such as navigating to inaccessible pages. Defaults to `false`. - trial : Union[bool, None] + trial : Optional[bool] When set, this method only performs the [actionability](../actionability.md) checks and skips the action. Defaults to `false`. Useful to wait until the element is ready for the action without performing it. """ @@ -2205,14 +2205,14 @@ async def fill( ---------- value : str Value to set for the ``, `