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..2e54af2e5 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,
- 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,
- recordHarPath: Union[Path, str] = None,
- recordHarOmitContent: bool = None,
- recordVideoDir: Union[Path, str] = None,
- recordVideoSize: ViewportSize = None,
- storageState: Union[StorageState, str, Path] = None,
- baseURL: str = None,
- strictSelectors: bool = None,
- serviceWorkers: ServiceWorkersPolicy = None,
- recordHarUrlFilter: Union[Pattern[str], str] = None,
- recordHarMode: HarMode = None,
- recordHarContent: HarContentPolicy = 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: Optional[Sequence[str]] = None,
+ extraHTTPHeaders: Optional[Dict[str, str]] = 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: Optional[Union[Path, str]] = None,
+ recordHarOmitContent: Optional[bool] = None,
+ recordVideoDir: Optional[Union[Path, str]] = None,
+ recordVideoSize: Optional[ViewportSize] = None,
+ storageState: Optional[Union[StorageState, str, Path]] = None,
+ baseURL: Optional[str] = None,
+ strictSelectors: Optional[bool] = None,
+ serviceWorkers: Optional[ServiceWorkersPolicy] = None,
+ recordHarUrlFilter: Optional[Union[Pattern[str], str]] = 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,
- 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,
- recordHarPath: Union[Path, str] = None,
- recordHarOmitContent: bool = None,
- recordVideoDir: Union[Path, str] = None,
- recordVideoSize: ViewportSize = None,
- storageState: Union[StorageState, str, Path] = None,
- baseURL: str = None,
- strictSelectors: bool = None,
- serviceWorkers: ServiceWorkersPolicy = None,
- recordHarUrlFilter: Union[Pattern[str], str] = None,
- recordHarMode: HarMode = None,
- recordHarContent: HarContentPolicy = 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: Optional[Sequence[str]] = None,
+ extraHTTPHeaders: Optional[Dict[str, str]] = 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: Optional[Union[Path, str]] = None,
+ recordHarOmitContent: Optional[bool] = None,
+ recordVideoDir: Optional[Union[Path, str]] = None,
+ recordVideoSize: Optional[ViewportSize] = None,
+ storageState: Optional[Union[StorageState, str, Path]] = None,
+ baseURL: Optional[str] = None,
+ strictSelectors: Optional[bool] = None,
+ serviceWorkers: Optional[ServiceWorkersPolicy] = None,
+ recordHarUrlFilter: Optional[Union[Pattern[str], str]] = 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,10 +197,10 @@ async def new_browser_cdp_session(self) -> CDPSession:
async def start_tracing(
self,
- page: Page = None,
- path: Union[str, Path] = None,
- screenshots: bool = None,
- categories: Sequence[str] = None,
+ page: Optional[Page] = None,
+ path: Optional[Union[str, Path]] = None,
+ screenshots: Optional[bool] = None,
+ categories: Optional[Sequence[str]] = None,
) -> None:
params = locals_to_params(locals())
if page:
diff --git a/playwright/_impl/_browser_context.py b/playwright/_impl/_browser_context.py
index 6ea934323..9bd3e5c1a 100644
--- a/playwright/_impl/_browser_context.py
+++ b/playwright/_impl/_browser_context.py
@@ -306,14 +306,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:
@@ -325,7 +325,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()
@@ -334,7 +334,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:
@@ -352,7 +352,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,
@@ -381,7 +381,7 @@ async def _unroute_internal(
self,
removed: List[RouteHandler],
remaining: List[RouteHandler],
- behavior: Literal["default", "ignoreErrors", "wait"] = None,
+ behavior: Optional[Literal["default", "ignoreErrors", "wait"]] = None,
) -> None:
self._routes = remaining
await self._update_interception_patterns()
@@ -395,7 +395,7 @@ def _dispose_har_routers(self) -> None:
self._har_routers = []
async def unroute_all(
- self, behavior: Literal["default", "ignoreErrors", "wait"] = None
+ self, behavior: Optional[Literal["default", "ignoreErrors", "wait"]] = None
) -> None:
await self._unroute_internal(self._routes, [], behavior)
self._dispose_har_routers()
@@ -404,9 +404,9 @@ async def _record_into_har(
self,
har: Union[Path, str],
page: Optional[Page] = None,
- url: Union[Pattern[str], str] = None,
- update_content: HarContentPolicy = None,
- update_mode: HarMode = None,
+ url: Optional[Union[Pattern[str], str]] = None,
+ update_content: Optional[HarContentPolicy] = None,
+ update_mode: Optional[HarMode] = None,
) -> None:
params: Dict[str, Any] = {
"options": prepare_record_har_options(
@@ -429,11 +429,11 @@ async def _record_into_har(
async def route_from_har(
self,
har: Union[Path, str],
- url: Union[Pattern[str], str] = None,
- notFound: RouteFromHarNotFoundPolicy = None,
- update: bool = None,
- updateContent: Literal["attach", "embed"] = None,
- updateMode: HarMode = None,
+ url: Optional[Union[Pattern[str], str]] = None,
+ notFound: Optional[RouteFromHarNotFoundPolicy] = None,
+ update: Optional[bool] = None,
+ updateContent: Optional[Literal["attach", "embed"]] = None,
+ updateMode: Optional[HarMode] = None,
) -> None:
if update:
await self._record_into_har(
@@ -462,8 +462,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()
@@ -485,7 +485,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
@@ -532,7 +532,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
@@ -540,15 +543,15 @@ async def wait_for_event(
def expect_console_message(
self,
- predicate: Callable[[ConsoleMessage], bool] = None,
- timeout: float = None,
+ predicate: Optional[Callable[[ConsoleMessage], bool]] = 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,
+ predicate: Optional[Callable[[Page], bool]] = 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..1d164cf41 100644
--- a/playwright/_impl/_browser_type.py
+++ b/playwright/_impl/_browser_type.py
@@ -70,23 +70,23 @@ def executable_path(self) -> str:
async def launch(
self,
- executablePath: Union[str, Path] = None,
- channel: 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,
- downloadsPath: Union[str, Path] = None,
- slowMo: float = None,
- tracesDir: Union[pathlib.Path, str] = None,
- chromiumSandbox: bool = None,
- firefoxUserPrefs: Dict[str, Union[str, float, bool]] = None,
+ executablePath: Optional[Union[str, Path]] = None,
+ channel: Optional[str] = None,
+ args: Optional[Sequence[str]] = None,
+ ignoreDefaultArgs: Optional[Union[bool, Sequence[str]]] = 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: Optional[Union[str, Path]] = None,
+ slowMo: Optional[float] = None,
+ tracesDir: Optional[Union[pathlib.Path, str]] = None,
+ chromiumSandbox: Optional[bool] = None,
+ firefoxUserPrefs: Optional[Dict[str, Union[str, float, bool]]] = None,
) -> Browser:
params = locals_to_params(locals())
normalize_launch_params(params)
@@ -99,54 +99,54 @@ async def launch(
async def launch_persistent_context(
self,
userDataDir: Union[str, Path],
- channel: 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,
- 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,
- 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,
- tracesDir: Union[pathlib.Path, str] = None,
- chromiumSandbox: bool = None,
- firefoxUserPrefs: Dict[str, Union[str, float, bool]] = None,
- recordHarPath: Union[Path, str] = None,
- recordHarOmitContent: bool = None,
- recordVideoDir: Union[Path, str] = None,
- recordVideoSize: ViewportSize = None,
- baseURL: str = None,
- strictSelectors: bool = None,
- serviceWorkers: ServiceWorkersPolicy = None,
- recordHarUrlFilter: Union[Pattern[str], str] = None,
- recordHarMode: HarMode = None,
- recordHarContent: HarContentPolicy = None,
+ channel: Optional[str] = None,
+ executablePath: Optional[Union[str, Path]] = None,
+ args: Optional[Sequence[str]] = None,
+ ignoreDefaultArgs: Optional[Union[bool, Sequence[str]]] = 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: Optional[Union[str, Path]] = 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: Optional[Sequence[str]] = None,
+ extraHTTPHeaders: Optional[Dict[str, str]] = 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: Optional[Union[pathlib.Path, str]] = None,
+ chromiumSandbox: Optional[bool] = None,
+ firefoxUserPrefs: Optional[Dict[str, Union[str, float, bool]]] = None,
+ recordHarPath: Optional[Union[Path, str]] = None,
+ recordHarOmitContent: Optional[bool] = None,
+ recordVideoDir: Optional[Union[Path, str]] = None,
+ recordVideoSize: Optional[ViewportSize] = None,
+ baseURL: Optional[str] = None,
+ strictSelectors: Optional[bool] = None,
+ serviceWorkers: Optional[ServiceWorkersPolicy] = None,
+ recordHarUrlFilter: Optional[Union[Pattern[str], str]] = None,
+ recordHarMode: Optional[HarMode] = None,
+ recordHarContent: Optional[HarContentPolicy] = None,
) -> BrowserContext:
userDataDir = str(Path(userDataDir)) if userDataDir else ""
params = locals_to_params(locals())
@@ -162,9 +162,9 @@ async def launch_persistent_context(
async def connect_over_cdp(
self,
endpointURL: str,
- timeout: float = None,
- slowMo: float = None,
- headers: Dict[str, str] = None,
+ timeout: Optional[float] = None,
+ slowMo: Optional[float] = None,
+ headers: Optional[Dict[str, str]] = None,
) -> Browser:
params = locals_to_params(locals())
if params.get("headers"):
@@ -184,10 +184,10 @@ async def connect_over_cdp(
async def connect(
self,
wsEndpoint: str,
- timeout: float = None,
- slowMo: float = None,
- headers: Dict[str, str] = None,
- exposeNetwork: str = None,
+ timeout: Optional[float] = None,
+ slowMo: Optional[float] = None,
+ headers: Optional[Dict[str, 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 444329a44..21ae4ee50 100644
--- a/playwright/_impl/_connection.py
+++ b/playwright/_impl/_connection.py
@@ -54,17 +54,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(
@@ -283,7 +285,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 74e5bdff9..906f37d9d 100644
--- a/playwright/_impl/_element_handle.py
+++ b/playwright/_impl/_element_handle.py
@@ -98,61 +98,61 @@ 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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
async def select_option(
self,
- value: Union[str, Sequence[str]] = None,
- 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,
+ value: Optional[Union[str, Sequence[str]]] = None,
+ index: Optional[Union[int, Sequence[int]]] = None,
+ label: Optional[Union[str, Sequence[str]]] = None,
+ element: Optional[Union["ElementHandle", Sequence["ElementHandle"]]] = None,
+ timeout: Optional[float] = None,
+ force: Optional[bool] = None,
+ noWaitAfter: Optional[bool] = None,
) -> List[str]:
params = locals_to_params(
dict(
@@ -166,28 +166,30 @@ 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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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(
@@ -195,8 +197,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:
@@ -217,29 +219,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(
@@ -260,21 +262,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()))
@@ -283,17 +285,17 @@ async def bounding_box(self) -> Optional[FloatRect]:
async def screenshot(
self,
- timeout: float = None,
- type: Literal["jpeg", "png"] = None,
- path: Union[str, Path] = None,
- quality: int = None,
- omitBackground: 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,
+ timeout: Optional[float] = None,
+ type: Optional[Literal["jpeg", "png"]] = None,
+ path: Optional[Union[str, Path]] = None,
+ quality: Optional[int] = None,
+ omitBackground: Optional[bool] = None,
+ animations: Optional[Literal["allow", "disabled"]] = None,
+ caret: Optional[Literal["hide", "initial"]] = None,
+ scale: Optional[Literal["css", "device"]] = None,
+ mask: Optional[Sequence["Locator"]] = None,
+ maskColor: Optional[str] = None,
+ style: Optional[str] = None,
) -> bytes:
params = locals_to_params(locals())
if "path" in params:
@@ -334,7 +336,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(
@@ -351,7 +353,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(
@@ -369,16 +371,16 @@ 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()))
async def wait_for_selector(
self,
selector: str,
- state: Literal["attached", "detached", "hidden", "visible"] = None,
- timeout: float = None,
- strict: bool = None,
+ state: Optional[Literal["attached", "detached", "hidden", "visible"]] = None,
+ timeout: Optional[float] = None,
+ strict: Optional[bool] = None,
) -> Optional["ElementHandle"]:
return from_nullable_channel(
await self._channel.send("waitForSelector", locals_to_params(locals()))
@@ -386,16 +388,16 @@ async def wait_for_selector(
def convert_select_option_values(
- value: Union[str, Sequence[str]] = None,
- index: Union[int, Sequence[int]] = None,
- label: Union[str, Sequence[str]] = None,
- element: Union["ElementHandle", Sequence["ElementHandle"]] = None,
+ value: Optional[Union[str, Sequence[str]]] = None,
+ index: Optional[Union[int, Sequence[int]]] = None,
+ label: Optional[Union[str, Sequence[str]]] = None,
+ element: Optional[Union["ElementHandle", Sequence["ElementHandle"]]] = None,
) -> Any:
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..35a8178a9 100644
--- a/playwright/_impl/_fetch.py
+++ b/playwright/_impl/_fetch.py
@@ -15,9 +15,8 @@
import base64
import json
import pathlib
-import typing
from pathlib import Path
-from typing import Any, Dict, List, Optional, Union, cast
+from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union, cast
import playwright._impl._network as network
from playwright._impl._api_structures import (
@@ -44,7 +43,7 @@
from playwright._impl._network import serialize_headers
from playwright._impl._tracing import Tracing
-if typing.TYPE_CHECKING:
+if TYPE_CHECKING:
from playwright._impl._playwright import Playwright
@@ -62,14 +61,14 @@ def __init__(self, playwright: "Playwright") -> None:
async def new_context(
self,
- baseURL: str = None,
- extraHTTPHeaders: Dict[str, str] = None,
- httpCredentials: HttpCredentials = None,
- ignoreHTTPSErrors: bool = None,
- proxy: ProxySettings = None,
- userAgent: str = None,
- timeout: float = None,
- storageState: Union[StorageState, str, Path] = None,
+ baseURL: Optional[str] = None,
+ extraHTTPHeaders: Optional[Dict[str, str]] = None,
+ httpCredentials: Optional[HttpCredentials] = None,
+ ignoreHTTPSErrors: Optional[bool] = None,
+ proxy: Optional[ProxySettings] = None,
+ userAgent: Optional[str] = None,
+ timeout: Optional[float] = None,
+ storageState: Optional[Union[StorageState, str, Path]] = None,
) -> "APIRequestContext":
params = locals_to_params(locals())
if "storageState" in params:
@@ -100,15 +99,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 +126,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 +153,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 +180,17 @@ async def get(
async def patch(
self,
url: str,
- params: ParamsType = None,
- headers: Headers = None,
- data: DataType = None,
- form: FormType = None,
- multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = 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[
+ Dict[str, Union[bytes, bool, float, str, FilePayload]]
+ ] = 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 +209,17 @@ async def patch(
async def put(
self,
url: str,
- params: ParamsType = None,
- headers: Headers = None,
- data: DataType = None,
- form: FormType = None,
- multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = 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[
+ Dict[str, Union[bytes, bool, float, str, FilePayload]]
+ ] = 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 +238,17 @@ async def put(
async def post(
self,
url: str,
- params: ParamsType = None,
- headers: Headers = None,
- data: DataType = None,
- form: FormType = None,
- multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = 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[
+ Dict[str, Union[bytes, bool, float, str, FilePayload]]
+ ] = 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 +267,18 @@ 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,
- multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = None,
- timeout: float = None,
- failOnStatusCode: bool = None,
- ignoreHTTPSErrors: bool = None,
- maxRedirects: int = None,
+ params: Optional[ParamsType] = None,
+ method: Optional[str] = None,
+ headers: Optional[Headers] = None,
+ data: Optional[DataType] = None,
+ form: Optional[FormType] = None,
+ multipart: Optional[
+ Dict[str, Union[bytes, bool, float, str, FilePayload]]
+ ] = 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 +308,18 @@ 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,
- multipart: Dict[str, Union[bytes, bool, float, str, FilePayload]] = None,
- timeout: float = None,
- failOnStatusCode: bool = None,
- ignoreHTTPSErrors: bool = None,
- maxRedirects: int = None,
+ method: Optional[str] = None,
+ headers: Optional[Headers] = None,
+ data: Optional[DataType] = None,
+ params: Optional[ParamsType] = None,
+ form: Optional[FormType] = None,
+ multipart: Optional[
+ Dict[str, Union[bytes, bool, float, str, FilePayload]]
+ ] = 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 +332,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 556395a5b..fae0b8fac 100644
--- a/playwright/_impl/_frame.py
+++ b/playwright/_impl/_frame.py
@@ -104,7 +104,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)
@@ -134,9 +136,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],
@@ -145,7 +147,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(
@@ -169,9 +173,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:
@@ -221,8 +225,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)
@@ -236,13 +240,13 @@ async def wait_for_url(
async def wait_for_load_state(
self,
- state: Literal["domcontentloaded", "load", "networkidle"] = None,
- timeout: float = None,
+ state: Optional[Literal["domcontentloaded", "load", "networkidle"]] = 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"
@@ -272,7 +276,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",
@@ -284,7 +290,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(
@@ -297,7 +303,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()))
@@ -314,41 +320,59 @@ async def query_selector_all(self, selector: str) -> List[ElementHandle]:
async def wait_for_selector(
self,
selector: str,
- strict: bool = None,
- timeout: float = None,
- state: Literal["attached", "detached", "hidden", "visible"] = None,
+ strict: Optional[bool] = None,
+ timeout: Optional[float] = None,
+ state: Optional[Literal["attached", "detached", "hidden", "visible"]] = None,
) -> Optional[ElementHandle]:
return from_nullable_channel(
await self._channel.send("waitForSelector", 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._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()))
@@ -356,9 +380,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",
@@ -377,8 +401,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(
@@ -398,7 +422,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(
@@ -417,8 +441,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()))
@@ -443,10 +467,10 @@ def is_detached(self) -> bool:
async def add_script_tag(
self,
- url: str = None,
- path: Union[str, Path] = None,
- content: str = None,
- type: str = None,
+ url: Optional[str] = None,
+ path: Optional[Union[str, Path]] = None,
+ content: Optional[str] = None,
+ type: Optional[str] = None,
) -> ElementHandle:
params = locals_to_params(locals())
if path:
@@ -459,7 +483,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: Optional[Union[str, Path]] = None,
+ content: Optional[str] = None,
) -> ElementHandle:
params = locals_to_params(locals())
if path:
@@ -475,44 +502,44 @@ async def add_style_tag(
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
@@ -520,20 +547,20 @@ 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()))
def locator(
self,
selector: str,
- hasText: Union[str, Pattern[str]] = None,
- hasNotText: Union[str, Pattern[str]] = None,
- has: Locator = None,
- hasNot: Locator = None,
+ hasText: Optional[Union[str, Pattern[str]]] = None,
+ hasNotText: Optional[Union[str, Pattern[str]]] = None,
+ has: Optional[Locator] = None,
+ hasNot: Optional[Locator] = None,
) -> Locator:
return Locator(
self,
@@ -545,32 +572,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,
- name: Union[str, Pattern[str]] = None,
- pressed: bool = None,
- selected: bool = None,
- exact: bool = None,
+ checked: Optional[bool] = None,
+ disabled: Optional[bool] = None,
+ expanded: Optional[bool] = None,
+ includeHidden: Optional[bool] = None,
+ level: Optional[int] = None,
+ name: Optional[Union[str, Pattern[str]]] = None,
+ pressed: Optional[bool] = None,
+ selected: Optional[bool] = None,
+ exact: Optional[bool] = None,
) -> "Locator":
return self.locator(
get_by_role_selector(
@@ -591,12 +618,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))
@@ -604,40 +631,56 @@ 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()))
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
@@ -645,27 +688,27 @@ 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()))
async def select_option(
self,
selector: str,
- value: Union[str, Sequence[str]] = None,
- 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,
+ value: Optional[Union[str, Sequence[str]]] = None,
+ index: Optional[Union[int, Sequence[int]]] = None,
+ label: Optional[Union[str, Sequence[str]]] = None,
+ element: Optional[Union["ElementHandle", Sequence["ElementHandle"]]] = None,
+ timeout: Optional[float] = None,
+ noWaitAfter: Optional[bool] = None,
+ strict: Optional[bool] = None,
+ force: Optional[bool] = None,
) -> List[str]:
params = locals_to_params(
dict(
@@ -682,8 +725,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()))
@@ -693,9 +736,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(
@@ -713,10 +756,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()))
@@ -724,34 +767,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()))
@@ -761,9 +804,9 @@ async def wait_for_timeout(self, timeout: float) -> None:
async def wait_for_function(
self,
expression: str,
- arg: Serializable = None,
- timeout: float = None,
- polling: Union[float, Literal["raf"]] = None,
+ arg: Optional[Serializable] = None,
+ timeout: Optional[float] = None,
+ polling: Optional[Union[float, Literal["raf"]]] = None,
) -> JSHandle:
if isinstance(polling, str) and polling != "raf":
raise Error(f"Unknown polling option: {polling}")
@@ -780,12 +823,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 4fd92e6a2..1a2c5c006 100644
--- a/playwright/_impl/_helper.py
+++ b/playwright/_impl/_helper.py
@@ -137,7 +137,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):
@@ -177,7 +177,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 5d220f13b..ac286df87 100644
--- a/playwright/_impl/_locator.py
+++ b/playwright/_impl/_locator.py
@@ -66,8 +66,8 @@ def __init__(
self,
frame: "Frame",
selector: str,
- has_text: Union[str, Pattern[str]] = None,
- has_not_text: Union[str, Pattern[str]] = None,
+ has_text: Optional[Union[str, Pattern[str]]] = None,
+ has_not_text: Optional[Union[str, Pattern[str]]] = None,
has: "Locator" = None,
has_not: "Locator" = None,
) -> None:
@@ -101,7 +101,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
@@ -120,7 +120,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,
@@ -128,40 +130,40 @@ 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)
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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)
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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)
@@ -169,26 +171,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
@@ -197,26 +207,26 @@ 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)
def locator(
self,
selectorOrLocator: Union[str, "Locator"],
- hasText: Union[str, Pattern[str]] = None,
- hasNotText: Union[str, Pattern[str]] = None,
+ hasText: Optional[Union[str, Pattern[str]]] = None,
+ hasNotText: Optional[Union[str, Pattern[str]]] = None,
has: "Locator" = None,
hasNot: "Locator" = None,
) -> "Locator":
@@ -242,32 +252,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,
- name: Union[str, Pattern[str]] = None,
- pressed: bool = None,
- selected: bool = None,
- exact: bool = None,
+ checked: Optional[bool] = None,
+ disabled: Optional[bool] = None,
+ expanded: Optional[bool] = None,
+ includeHidden: Optional[bool] = None,
+ level: Optional[int] = None,
+ name: Optional[Union[str, Pattern[str]]] = None,
+ pressed: Optional[bool] = None,
+ selected: Optional[bool] = None,
+ exact: Optional[bool] = None,
) -> "Locator":
return self.locator(
get_by_role_selector(
@@ -288,12 +298,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))
@@ -302,7 +312,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(
@@ -327,8 +337,8 @@ def nth(self, index: int) -> "Locator":
def filter(
self,
- hasText: Union[str, Pattern[str]] = None,
- hasNotText: Union[str, Pattern[str]] = None,
+ hasText: Optional[Union[str, Pattern[str]]] = None,
+ hasNotText: Optional[Union[str, Pattern[str]]] = None,
has: "Locator" = None,
hasNot: "Locator" = None,
) -> "Locator":
@@ -357,11 +367,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",
{
@@ -387,12 +397,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"]
@@ -400,7 +410,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,
@@ -410,12 +422,12 @@ 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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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(
@@ -424,7 +436,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,
@@ -432,7 +444,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,
@@ -440,7 +452,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,
@@ -448,7 +460,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,
@@ -456,7 +468,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,
@@ -464,7 +476,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,
@@ -472,7 +484,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,
@@ -480,7 +492,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,
@@ -488,7 +500,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,
@@ -499,26 +511,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,
- type: Literal["jpeg", "png"] = None,
- path: Union[str, pathlib.Path] = None,
- quality: int = None,
- omitBackground: 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,
+ timeout: Optional[float] = None,
+ type: Optional[Literal["jpeg", "png"]] = None,
+ path: Optional[Union[str, pathlib.Path]] = None,
+ quality: Optional[int] = None,
+ omitBackground: Optional[bool] = None,
+ animations: Optional[Literal["allow", "disabled"]] = None,
+ caret: Optional[Literal["hide", "initial"]] = None,
+ scale: Optional[Literal["css", "device"]] = None,
+ mask: Optional[Sequence["Locator"]] = None,
+ maskColor: Optional[str] = None,
+ style: Optional[str] = None,
) -> bytes:
params = locals_to_params(locals())
return await self._with_element(
@@ -529,7 +541,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),
@@ -538,13 +550,13 @@ async def scroll_into_view_if_needed(
async def select_option(
self,
- value: Union[str, Sequence[str]] = None,
- 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,
+ value: Optional[Union[str, Sequence[str]]] = None,
+ index: Optional[Union[int, Sequence[int]]] = None,
+ label: Optional[Union[str, Sequence[str]]] = None,
+ element: Optional[Union["ElementHandle", Sequence["ElementHandle"]]] = 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(
@@ -553,7 +565,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}),
@@ -569,8 +583,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(
@@ -581,12 +595,12 @@ 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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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(
@@ -595,7 +609,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,
@@ -606,9 +620,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(
@@ -620,19 +634,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(
@@ -657,8 +671,8 @@ async def all_text_contents(
async def wait_for(
self,
- timeout: float = None,
- state: Literal["attached", "detached", "hidden", "visible"] = None,
+ timeout: Optional[float] = None,
+ state: Optional[Literal["attached", "detached", "hidden", "visible"]] = None,
) -> None:
await self._frame.wait_for_selector(
self._selector, strict=True, timeout=timeout, state=state
@@ -667,11 +681,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(
@@ -721,10 +735,10 @@ def __init__(self, frame: "Frame", frame_selector: str) -> None:
def locator(
self,
selectorOrLocator: Union["Locator", str],
- hasText: Union[str, Pattern[str]] = None,
- hasNotText: Union[str, Pattern[str]] = None,
- has: Locator = None,
- hasNot: Locator = None,
+ hasText: Optional[Union[str, Pattern[str]]] = None,
+ hasNotText: Optional[Union[str, Pattern[str]]] = None,
+ has: Optional[Locator] = None,
+ hasNot: Optional[Locator] = None,
) -> Locator:
if isinstance(selectorOrLocator, str):
return Locator(
@@ -748,32 +762,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,
- name: Union[str, Pattern[str]] = None,
- pressed: bool = None,
- selected: bool = None,
- exact: bool = None,
+ checked: Optional[bool] = None,
+ disabled: Optional[bool] = None,
+ expanded: Optional[bool] = None,
+ includeHidden: Optional[bool] = None,
+ level: Optional[int] = None,
+ name: Optional[Union[str, Pattern[str]]] = None,
+ pressed: Optional[bool] = None,
+ selected: Optional[bool] = None,
+ exact: Optional[bool] = None,
) -> "Locator":
return self.locator(
get_by_role_selector(
@@ -794,12 +808,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))
@@ -843,30 +857,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)
@@ -876,15 +898,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,
- name: Union[str, Pattern[str]] = None,
- pressed: bool = None,
- selected: bool = None,
- exact: bool = None,
+ checked: Optional[bool] = None,
+ disabled: Optional[bool] = None,
+ expanded: Optional[bool] = None,
+ includeHidden: Optional[bool] = None,
+ level: Optional[int] = None,
+ name: Optional[Union[str, Pattern[str]]] = 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 ecce43571..25d76e29b 100644
--- a/playwright/_impl/_network.py
+++ b/playwright/_impl/_network.py
@@ -295,7 +295,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(
@@ -310,12 +310,12 @@ async def abort(self, errorCode: str = None) -> None:
async def fulfill(
self,
- status: int = None,
- headers: Dict[str, str] = None,
- body: Union[str, bytes] = None,
- json: Any = None,
- path: Union[str, Path] = None,
- contentType: str = None,
+ status: Optional[int] = None,
+ headers: Optional[Dict[str, str]] = None,
+ body: Optional[Union[str, bytes]] = None,
+ json: Optional[Any] = None,
+ path: Optional[Union[str, Path]] = None,
+ contentType: Optional[str] = None,
response: "APIResponse" = None,
) -> None:
await self._handle_route(
@@ -326,12 +326,12 @@ async def fulfill(
async def _inner_fulfill(
self,
- status: int = None,
- headers: Dict[str, str] = None,
- body: Union[str, bytes] = None,
- json: Any = None,
- path: Union[str, Path] = None,
- contentType: str = None,
+ status: Optional[int] = None,
+ headers: Optional[Dict[str, str]] = None,
+ body: Optional[Union[str, bytes]] = None,
+ json: Optional[Any] = None,
+ path: Optional[Union[str, Path]] = None,
+ contentType: Optional[str] = None,
response: "APIResponse" = None,
) -> None:
params = locals_to_params(locals())
@@ -400,12 +400,12 @@ async def _handle_route(self, callback: Callable) -> None:
async def fetch(
self,
- url: str = None,
- method: str = None,
- headers: Dict[str, str] = None,
- postData: Union[Any, str, bytes] = None,
- maxRedirects: int = None,
- timeout: float = None,
+ url: Optional[str] = None,
+ method: Optional[str] = None,
+ headers: Optional[Dict[str, str]] = None,
+ postData: Optional[Union[Any, str, bytes]] = None,
+ maxRedirects: Optional[int] = None,
+ timeout: Optional[float] = None,
) -> "APIResponse":
return await self._connection.wrap_api_call(
lambda: self._context.request._inner_fetch(
@@ -421,10 +421,10 @@ async def fetch(
async def fallback(
self,
- url: str = None,
- method: str = None,
- headers: Dict[str, str] = None,
- postData: Union[Any, str, bytes] = None,
+ url: Optional[str] = None,
+ method: Optional[str] = None,
+ headers: Optional[Dict[str, str]] = None,
+ postData: Optional[Union[Any, str, bytes]] = None,
) -> None:
overrides = cast(FallbackOverrideParameters, locals_to_params(locals()))
self._check_not_handled()
@@ -433,10 +433,10 @@ async def fallback(
async def continue_(
self,
- url: str = None,
- method: str = None,
- headers: Dict[str, str] = None,
- postData: Union[Any, str, bytes] = None,
+ url: Optional[str] = None,
+ method: Optional[str] = None,
+ headers: Optional[Dict[str, str]] = None,
+ postData: Optional[Union[Any, str, bytes]] = None,
) -> None:
overrides = cast(FallbackOverrideParameters, locals_to_params(locals()))
@@ -656,8 +656,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()
@@ -677,7 +677,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 cffde68c1..76d96588c 100644
--- a/playwright/_impl/_page.py
+++ b/playwright/_impl/_page.py
@@ -306,7 +306,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
@@ -336,7 +338,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)
@@ -346,39 +348,57 @@ async def query_selector_all(self, selector: str) -> List[ElementHandle]:
async def wait_for_selector(
self,
selector: str,
- timeout: float = None,
- state: Literal["attached", "detached", "hidden", "visible"] = None,
- strict: bool = None,
+ timeout: Optional[float] = None,
+ state: Optional[Literal["attached", "detached", "hidden", "visible"]] = 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()))
@@ -386,17 +406,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)
@@ -404,8 +426,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
@@ -415,21 +437,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,
- path: Union[str, Path] = None,
- content: str = None,
- type: str = None,
+ url: Optional[str] = None,
+ path: Optional[Union[str, Path]] = 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: Optional[Union[str, Path]] = None,
+ content: Optional[str] = None,
) -> ElementHandle:
return await self._main_frame.add_style_tag(**locals_to_params(locals()))
@@ -437,7 +462,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')
@@ -465,24 +490,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()))
@@ -490,21 +515,24 @@ async def reload(
async def wait_for_load_state(
self,
- state: Literal["domcontentloaded", "load", "networkidle"] = None,
- timeout: float = None,
+ state: Optional[Literal["domcontentloaded", "load", "networkidle"]] = 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
@@ -512,8 +540,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()))
@@ -521,8 +549,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()))
@@ -530,10 +558,10 @@ async def go_forward(
async def emulate_media(
self,
- media: Literal["null", "print", "screen"] = None,
- colorScheme: ColorScheme = None,
- reducedMotion: ReducedMotion = None,
- forcedColors: ForcedColors = None,
+ media: Optional[Literal["null", "print", "screen"]] = None,
+ colorScheme: Optional[ColorScheme] = None,
+ reducedMotion: Optional[ReducedMotion] = None,
+ forcedColors: Optional[ForcedColors] = None,
) -> None:
params = locals_to_params(locals())
if "media" in params:
@@ -564,7 +592,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()
@@ -573,7 +601,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,
@@ -602,7 +630,7 @@ async def _unroute_internal(
self,
removed: List[RouteHandler],
remaining: List[RouteHandler],
- behavior: Literal["default", "ignoreErrors", "wait"] = None,
+ behavior: Optional[Literal["default", "ignoreErrors", "wait"]] = None,
) -> None:
self._routes = remaining
await self._update_interception_patterns()
@@ -621,7 +649,7 @@ def _dispose_har_routers(self) -> None:
self._har_routers = []
async def unroute_all(
- self, behavior: Literal["default", "ignoreErrors", "wait"] = None
+ self, behavior: Optional[Literal["default", "ignoreErrors", "wait"]] = None
) -> None:
await self._unroute_internal(self._routes, [], behavior)
self._dispose_har_routers()
@@ -629,11 +657,11 @@ async def unroute_all(
async def route_from_har(
self,
har: Union[Path, str],
- url: Union[Pattern[str], str] = None,
- notFound: RouteFromHarNotFoundPolicy = None,
- update: bool = None,
- updateContent: Literal["attach", "embed"] = None,
- updateMode: HarMode = None,
+ url: Optional[Union[Pattern[str], str]] = None,
+ notFound: Optional[RouteFromHarNotFoundPolicy] = None,
+ update: Optional[bool] = None,
+ updateContent: Optional[Literal["attach", "embed"]] = None,
+ updateMode: Optional[HarMode] = None,
) -> None:
if update:
await self._browser_context._record_into_har(
@@ -661,19 +689,19 @@ async def _update_interception_patterns(self) -> None:
async def screenshot(
self,
- timeout: float = None,
- type: Literal["jpeg", "png"] = None,
- path: Union[str, Path] = None,
- quality: int = None,
- omitBackground: bool = None,
- fullPage: bool = None,
- clip: 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,
+ timeout: Optional[float] = None,
+ type: Optional[Literal["jpeg", "png"]] = None,
+ path: Optional[Union[str, Path]] = None,
+ quality: Optional[int] = None,
+ omitBackground: Optional[bool] = None,
+ fullPage: Optional[bool] = None,
+ clip: Optional[FloatRect] = None,
+ animations: Optional[Literal["allow", "disabled"]] = None,
+ caret: Optional[Literal["hide", "initial"]] = None,
+ scale: Optional[Literal["css", "device"]] = None,
+ mask: Optional[Sequence["Locator"]] = None,
+ maskColor: Optional[str] = None,
+ style: Optional[str] = None,
) -> bytes:
params = locals_to_params(locals())
if "path" in params:
@@ -700,7 +728,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:
@@ -717,44 +747,44 @@ def is_closed(self) -> bool:
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
@@ -762,18 +792,18 @@ 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()))
def locator(
self,
selector: str,
- hasText: Union[str, Pattern[str]] = None,
- hasNotText: Union[str, Pattern[str]] = None,
+ hasText: Optional[Union[str, Pattern[str]]] = None,
+ hasNotText: Optional[Union[str, Pattern[str]]] = None,
has: "Locator" = None,
hasNot: "Locator" = None,
) -> "Locator":
@@ -786,32 +816,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,
- name: Union[str, Pattern[str]] = None,
- pressed: bool = None,
- selected: bool = None,
- exact: bool = None,
+ checked: Optional[bool] = None,
+ disabled: Optional[bool] = None,
+ expanded: Optional[bool] = None,
+ includeHidden: Optional[bool] = None,
+ level: Optional[int] = None,
+ name: Optional[Union[str, Pattern[str]]] = None,
+ pressed: Optional[bool] = None,
+ selected: Optional[bool] = None,
+ exact: Optional[bool] = None,
) -> "Locator":
return self._main_frame.get_by_role(
role,
@@ -830,12 +860,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)
@@ -843,40 +873,56 @@ 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()))
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,
+ modifiers: Optional[Sequence[KeyboardModifier]] = 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()))
@@ -884,33 +930,36 @@ 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()))
async def select_option(
self,
selector: str,
- value: Union[str, Sequence[str]] = None,
- 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,
+ value: Optional[Union[str, Sequence[str]]] = None,
+ index: Optional[Union[int, Sequence[int]]] = None,
+ label: Optional[Union[str, Sequence[str]]] = None,
+ element: Optional[Union["ElementHandle", Sequence["ElementHandle"]]] = 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)
@@ -921,9 +970,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()))
@@ -931,10 +980,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()))
@@ -942,34 +991,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()))
@@ -979,9 +1028,9 @@ async def wait_for_timeout(self, timeout: float) -> None:
async def wait_for_function(
self,
expression: str,
- arg: Serializable = None,
- timeout: float = None,
- polling: Union[float, Literal["raf"]] = None,
+ arg: Optional[Serializable] = None,
+ timeout: Optional[float] = None,
+ polling: Optional[Union[float, Literal["raf"]]] = None,
) -> JSHandle:
return await self._main_frame.wait_for_function(**locals_to_params(locals()))
@@ -1016,19 +1065,19 @@ 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,
- width: Union[str, float] = None,
- height: Union[str, float] = None,
- preferCSSPageSize: bool = None,
- margin: PdfMargins = None,
- path: Union[str, Path] = 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: Optional[Union[str, float]] = None,
+ height: Optional[Union[str, float]] = None,
+ preferCSSPageSize: Optional[bool] = None,
+ margin: Optional[PdfMargins] = None,
+ path: Optional[Union[str, Path]] = None,
) -> bytes:
params = locals_to_params(locals())
if "path" in params:
@@ -1056,8 +1105,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}"'
@@ -1066,9 +1115,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()
@@ -1089,44 +1138,44 @@ def _expect_event(
def expect_console_message(
self,
- predicate: Callable[[ConsoleMessage], bool] = None,
- timeout: float = None,
+ predicate: Optional[Callable[[ConsoleMessage], bool]] = 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,
+ predicate: Optional[Callable[[Download], bool]] = 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,
+ predicate: Optional[Callable[[FileChooser], bool]] = 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,
+ predicate: Optional[Callable[["Page"], bool]] = 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
@@ -1155,8 +1204,8 @@ def my_predicate(request: Request) -> bool:
def expect_request_finished(
self,
- predicate: Callable[["Request"], bool] = None,
- timeout: float = None,
+ predicate: Optional[Callable[["Request"], bool]] = None,
+ timeout: Optional[float] = None,
) -> EventContextManagerImpl[Request]:
return self.expect_event(
Page.Events.RequestFinished, predicate=predicate, timeout=timeout
@@ -1165,7 +1214,7 @@ def expect_request_finished(
def expect_response(
self,
urlOrPredicate: URLMatchResponse,
- timeout: float = None,
+ timeout: Optional[float] = None,
) -> EventContextManagerImpl[Response]:
matcher = (
None
@@ -1194,15 +1243,15 @@ def my_predicate(response: Response) -> bool:
def expect_websocket(
self,
- predicate: Callable[["WebSocket"], bool] = None,
- timeout: float = None,
+ predicate: Optional[Callable[["WebSocket"], bool]] = 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,
+ predicate: Optional[Callable[["Worker"], bool]] = None,
+ timeout: Optional[float] = None,
) -> EventContextManagerImpl["Worker"]:
return self.expect_event("worker", predicate, timeout)
@@ -1210,12 +1259,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(
@@ -1264,7 +1313,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",
@@ -1276,7 +1327,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..fca6c0df5 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,
- path: Union[str, Path] = None,
- contentScript: bool = None,
+ script: Optional[str] = None,
+ path: Optional[Union[str, Path]] = 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)
diff --git a/playwright/async_api/_generated.py b/playwright/async_api/_generated.py
index f05e69639..25d9af4c1 100644
--- a/playwright/async_api/_generated.py
+++ b/playwright/async_api/_generated.py
@@ -14,8 +14,19 @@
import pathlib
-import typing
-from typing import Literal
+from typing import (
+ Any,
+ Awaitable,
+ Callable,
+ Dict,
+ List,
+ Literal,
+ Optional,
+ Pattern,
+ Sequence,
+ Union,
+ overload,
+)
from playwright._impl._accessibility import Accessibility as AccessibilityImpl
from playwright._impl._api_structures import (
@@ -121,19 +132,19 @@ def method(self) -> str:
return mapping.from_maybe_impl(self._impl_obj.method)
@property
- def post_data(self) -> typing.Optional[str]:
+ def post_data(self) -> Optional[str]:
"""Request.post_data
Request's post body, if any.
Returns
-------
- Union[str, None]
+ Optional[str]
"""
return mapping.from_maybe_impl(self._impl_obj.post_data)
@property
- def post_data_json(self) -> typing.Optional[typing.Any]:
+ def post_data_json(self) -> Optional[Any]:
"""Request.post_data_json
Returns parsed request's body for `form-urlencoded` and JSON as a fallback if any.
@@ -143,19 +154,19 @@ 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)
@property
- def post_data_buffer(self) -> typing.Optional[bytes]:
+ def post_data_buffer(self) -> Optional[bytes]:
"""Request.post_data_buffer
Request's post body in a binary form, if any.
Returns
-------
- Union[bytes, None]
+ Optional[bytes]
"""
return mapping.from_maybe_impl(self._impl_obj.post_data_buffer)
@@ -187,7 +198,7 @@ def frame(self) -> "Frame":
return mapping.from_impl(self._impl_obj.frame)
@property
- def redirected_from(self) -> typing.Optional["Request"]:
+ def redirected_from(self) -> Optional["Request"]:
"""Request.redirected_from
Request that was redirected by the server to this one, if any.
@@ -214,12 +225,12 @@ def redirected_from(self) -> typing.Optional["Request"]:
Returns
-------
- Union[Request, None]
+ Optional[Request]
"""
return mapping.from_impl_nullable(self._impl_obj.redirected_from)
@property
- def redirected_to(self) -> typing.Optional["Request"]:
+ def redirected_to(self) -> Optional["Request"]:
"""Request.redirected_to
New request issued by the browser if the server responded with redirect.
@@ -234,12 +245,12 @@ def redirected_to(self) -> typing.Optional["Request"]:
Returns
-------
- Union[Request, None]
+ Optional[Request]
"""
return mapping.from_impl_nullable(self._impl_obj.redirected_to)
@property
- def failure(self) -> typing.Optional[str]:
+ def failure(self) -> Optional[str]:
"""Request.failure
The method returns `null` unless this request has failed, as reported by `requestfailed` event.
@@ -254,7 +265,7 @@ def failure(self) -> typing.Optional[str]:
Returns
-------
- Union[str, None]
+ Optional[str]
"""
return mapping.from_maybe_impl(self._impl_obj.failure)
@@ -282,7 +293,7 @@ def timing(self) -> ResourceTiming:
return mapping.from_impl(self._impl_obj.timing)
@property
- def headers(self) -> typing.Dict[str, str]:
+ def headers(self) -> Dict[str, str]:
"""Request.headers
An object with the request HTTP headers. The header names are lower-cased. Note that this method does not return
@@ -307,14 +318,14 @@ async def sizes(self) -> RequestSizes:
return mapping.from_impl(await self._impl_obj.sizes())
- async def response(self) -> typing.Optional["Response"]:
+ async def response(self) -> Optional["Response"]:
"""Request.response
Returns the matching `Response` object, or `null` if the response was not received due to error.
Returns
-------
- Union[Response, None]
+ Optional[Response]
"""
return mapping.from_impl_nullable(await self._impl_obj.response())
@@ -334,7 +345,7 @@ def is_navigation_request(self) -> bool:
return mapping.from_maybe_impl(self._impl_obj.is_navigation_request())
- async def all_headers(self) -> typing.Dict[str, str]:
+ async def all_headers(self) -> Dict[str, str]:
"""Request.all_headers
An object with all the request HTTP headers associated with this request. The header names are lower-cased.
@@ -346,7 +357,7 @@ async def all_headers(self) -> typing.Dict[str, str]:
return mapping.from_maybe_impl(await self._impl_obj.all_headers())
- async def headers_array(self) -> typing.List[NameValue]:
+ async def headers_array(self) -> List[NameValue]:
"""Request.headers_array
An array with all the request HTTP headers associated with this request. Unlike `request.all_headers()`,
@@ -360,7 +371,7 @@ async def headers_array(self) -> typing.List[NameValue]:
return mapping.from_impl_list(await self._impl_obj.headers_array())
- async def header_value(self, name: str) -> typing.Optional[str]:
+ async def header_value(self, name: str) -> Optional[str]:
"""Request.header_value
Returns the value of the header matching the name. The name is case insensitive.
@@ -372,7 +383,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))
@@ -431,7 +442,7 @@ def status_text(self) -> str:
return mapping.from_maybe_impl(self._impl_obj.status_text)
@property
- def headers(self) -> typing.Dict[str, str]:
+ def headers(self) -> Dict[str, str]:
"""Response.headers
An object with the response HTTP headers. The header names are lower-cased. Note that this method does not return
@@ -481,7 +492,7 @@ def frame(self) -> "Frame":
"""
return mapping.from_impl(self._impl_obj.frame)
- async def all_headers(self) -> typing.Dict[str, str]:
+ async def all_headers(self) -> Dict[str, str]:
"""Response.all_headers
An object with all the response HTTP headers associated with this response.
@@ -493,7 +504,7 @@ async def all_headers(self) -> typing.Dict[str, str]:
return mapping.from_maybe_impl(await self._impl_obj.all_headers())
- async def headers_array(self) -> typing.List[NameValue]:
+ async def headers_array(self) -> List[NameValue]:
"""Response.headers_array
An array with all the request HTTP headers associated with this response. Unlike `response.all_headers()`,
@@ -507,7 +518,7 @@ async def headers_array(self) -> typing.List[NameValue]:
return mapping.from_impl_list(await self._impl_obj.headers_array())
- async def header_value(self, name: str) -> typing.Optional[str]:
+ async def header_value(self, name: str) -> Optional[str]:
"""Response.header_value
Returns the value of the header matching the name. The name is case insensitive. If multiple headers have the same
@@ -521,12 +532,12 @@ 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))
- async def header_values(self, name: str) -> typing.List[str]:
+ async def header_values(self, name: str) -> List[str]:
"""Response.header_values
Returns all values of the headers matching the name, for example `set-cookie`. The name is case insensitive.
@@ -543,7 +554,7 @@ async def header_values(self, name: str) -> typing.List[str]:
return mapping.from_maybe_impl(await self._impl_obj.header_values(name=name))
- async def server_addr(self) -> typing.Optional[RemoteAddr]:
+ async def server_addr(self) -> Optional[RemoteAddr]:
"""Response.server_addr
Returns the IP address and port of the server.
@@ -555,14 +566,14 @@ async def server_addr(self) -> typing.Optional[RemoteAddr]:
return mapping.from_impl_nullable(await self._impl_obj.server_addr())
- async def security_details(self) -> typing.Optional[SecurityDetails]:
+ async def security_details(self) -> Optional[SecurityDetails]:
"""Response.security_details
Returns SSL and other security information.
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())
@@ -599,7 +610,7 @@ async def text(self) -> str:
return mapping.from_maybe_impl(await self._impl_obj.text())
- async def json(self) -> typing.Any:
+ async def json(self) -> Any:
"""Response.json
Returns the JSON representation of response body.
@@ -630,14 +641,14 @@ def request(self) -> "Request":
"""
return mapping.from_impl(self._impl_obj.request)
- async def abort(self, error_code: typing.Optional[str] = None) -> None:
+ async def abort(self, error_code: Optional[str] = None) -> None:
"""Route.abort
Aborts the route's request.
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
@@ -662,13 +673,13 @@ async def abort(self, error_code: typing.Optional[str] = None) -> None:
async def fulfill(
self,
*,
- status: typing.Optional[int] = None,
- headers: typing.Optional[typing.Dict[str, str]] = None,
- body: typing.Optional[typing.Union[str, bytes]] = None,
- json: typing.Optional[typing.Any] = None,
- path: typing.Optional[typing.Union[str, pathlib.Path]] = None,
- content_type: typing.Optional[str] = None,
- response: typing.Optional["APIResponse"] = None
+ status: Optional[int] = None,
+ headers: Optional[Dict[str, str]] = None,
+ body: Optional[Union[str, bytes]] = None,
+ json: Optional[Any] = None,
+ path: Optional[Union[str, pathlib.Path]] = None,
+ content_type: Optional[str] = None,
+ response: Optional["APIResponse"] = None
) -> None:
"""Route.fulfill
@@ -693,20 +704,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.
"""
@@ -726,12 +737,12 @@ async def fulfill(
async def fetch(
self,
*,
- url: typing.Optional[str] = None,
- method: typing.Optional[str] = None,
- headers: typing.Optional[typing.Dict[str, str]] = None,
- post_data: typing.Optional[typing.Union[typing.Any, str, bytes]] = None,
- max_redirects: typing.Optional[int] = None,
- timeout: typing.Optional[float] = None
+ url: Optional[str] = None,
+ method: Optional[str] = None,
+ headers: Optional[Dict[str, str]] = None,
+ post_data: Optional[Union[Any, str, bytes]] = None,
+ max_redirects: Optional[int] = None,
+ timeout: Optional[float] = None
) -> "APIResponse":
"""Route.fetch
@@ -758,9 +769,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.
@@ -768,10 +779,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
@@ -793,10 +804,10 @@ async def handle(route):
async def fallback(
self,
*,
- url: typing.Optional[str] = None,
- method: typing.Optional[str] = None,
- headers: typing.Optional[typing.Dict[str, str]] = None,
- post_data: typing.Optional[typing.Union[typing.Any, str, bytes]] = None
+ url: Optional[str] = None,
+ method: Optional[str] = None,
+ headers: Optional[Dict[str, str]] = None,
+ post_data: Optional[Union[Any, str, bytes]] = None
) -> None:
"""Route.fallback
@@ -855,10 +866,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.
@@ -878,10 +889,10 @@ async def handle(route, request):
async def continue_(
self,
*,
- url: typing.Optional[str] = None,
- method: typing.Optional[str] = None,
- headers: typing.Optional[typing.Dict[str, str]] = None,
- post_data: typing.Optional[typing.Union[typing.Any, str, bytes]] = None
+ url: Optional[str] = None,
+ method: Optional[str] = None,
+ headers: Optional[Dict[str, str]] = None,
+ post_data: Optional[Union[Any, str, bytes]] = None
) -> None:
"""Route.continue_
@@ -910,9 +921,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.
@@ -934,42 +945,38 @@ async def handle(route, request):
class WebSocket(AsyncBase):
- @typing.overload
+ @overload
def on(
self,
event: Literal["close"],
- f: typing.Callable[["WebSocket"], "typing.Union[typing.Awaitable[None], None]"],
+ f: Callable[["WebSocket"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket closes."""
- @typing.overload
+ @overload
def on(
self,
event: Literal["framereceived"],
- f: typing.Callable[
- ["typing.Union[bytes, str]"], "typing.Union[typing.Awaitable[None], None]"
- ],
+ f: Callable[["Union[bytes, str]"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket receives a frame."""
- @typing.overload
+ @overload
def on(
self,
event: Literal["framesent"],
- f: typing.Callable[
- ["typing.Union[bytes, str]"], "typing.Union[typing.Awaitable[None], None]"
- ],
+ f: Callable[["Union[bytes, str]"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket sends a frame."""
- @typing.overload
+ @overload
def on(
self,
event: Literal["socketerror"],
- f: typing.Callable[["str"], "typing.Union[typing.Awaitable[None], None]"],
+ f: Callable[["str"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket has an error."""
@@ -977,46 +984,42 @@ def on(
def on(
self,
event: str,
- f: typing.Callable[..., typing.Union[typing.Awaitable[None], None]],
+ f: Callable[..., Optional[Awaitable[None]]],
) -> None:
return super().on(event=event, f=f)
- @typing.overload
+ @overload
def once(
self,
event: Literal["close"],
- f: typing.Callable[["WebSocket"], "typing.Union[typing.Awaitable[None], None]"],
+ f: Callable[["WebSocket"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket closes."""
- @typing.overload
+ @overload
def once(
self,
event: Literal["framereceived"],
- f: typing.Callable[
- ["typing.Union[bytes, str]"], "typing.Union[typing.Awaitable[None], None]"
- ],
+ f: Callable[["Union[bytes, str]"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket receives a frame."""
- @typing.overload
+ @overload
def once(
self,
event: Literal["framesent"],
- f: typing.Callable[
- ["typing.Union[bytes, str]"], "typing.Union[typing.Awaitable[None], None]"
- ],
+ f: Callable[["Union[bytes, str]"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket sends a frame."""
- @typing.overload
+ @overload
def once(
self,
event: Literal["socketerror"],
- f: typing.Callable[["str"], "typing.Union[typing.Awaitable[None], None]"],
+ f: Callable[["str"], "Optional[Awaitable[None]]"],
) -> None:
"""
Fired when the websocket has an error."""
@@ -1024,7 +1027,7 @@ def once(
def once(
self,
event: str,
- f: typing.Callable[..., typing.Union[typing.Awaitable[None], None]],
+ f: Callable[..., Optional[Awaitable[None]]],
) -> None:
return super().once(event=event, f=f)
@@ -1043,9 +1046,9 @@ def url(self) -> str:
def expect_event(
self,
event: str,
- predicate: typing.Optional[typing.Callable] = None,
+ predicate: Optional[Callable] = None,
*,
- timeout: typing.Optional[float] = None
+ timeout: Optional[float] = None
) -> AsyncEventContextManager:
"""WebSocket.expect_event
@@ -1056,9 +1059,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()`.
@@ -1076,10 +1079,10 @@ def expect_event(
async def wait_for_event(
self,
event: str,
- predicate: typing.Optional[typing.Callable] = None,
+ predicate: Optional[Callable] = None,
*,
- timeout: typing.Optional[float] = None
- ) -> typing.Any:
+ timeout: Optional[float] = None
+ ) -> Any:
"""WebSocket.wait_for_event
**NOTE** In most cases, you should use `web_socket.expect_event()`.
@@ -1092,9 +1095,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()`.
@@ -1199,7 +1202,7 @@ async def insert_text(self, text: str) -> None:
return mapping.from_maybe_impl(await self._impl_obj.insert_text(text=text))
- async def type(self, text: str, *, delay: typing.Optional[float] = None) -> None:
+ async def type(self, text: str, *, delay: Optional[float] = None) -> None:
"""Keyboard.type
**NOTE** In most cases, you should use `locator.fill()` instead. You only need to press keys one by one if
@@ -1224,7 +1227,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.
"""
@@ -1232,7 +1235,7 @@ async def type(self, text: str, *, delay: typing.Optional[float] = None) -> None
await self._impl_obj.type(text=text, delay=delay)
)
- async def press(self, key: str, *, delay: typing.Optional[float] = None) -> None:
+ async def press(self, key: str, *, delay: Optional[float] = None) -> None:
"""Keyboard.press
**NOTE** In most cases, you should use `locator.press()` instead.
@@ -1276,7 +1279,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.
"""
@@ -1287,9 +1290,7 @@ async def press(self, key: str, *, delay: typing.Optional[float] = None) -> None
class Mouse(AsyncBase):
- async def move(
- self, x: float, y: float, *, steps: typing.Optional[int] = None
- ) -> None:
+ async def move(self, x: float, y: float, *, steps: Optional[int] = None) -> None:
"""Mouse.move
Dispatches a `mousemove` event.
@@ -1298,7 +1299,7 @@ async def move(
----------
x : float
y : float
- steps : Union[int, None]
+ steps : Optional[int]
Defaults to 1. Sends intermediate `mousemove` events.
"""
@@ -1307,8 +1308,8 @@ async def move(
async def down(
self,
*,
- button: typing.Optional[Literal["left", "middle", "right"]] = None,
- click_count: typing.Optional[int] = None
+ button: Optional[Literal["left", "middle", "right"]] = None,
+ click_count: Optional[int] = None
) -> None:
"""Mouse.down
@@ -1318,7 +1319,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].
"""
@@ -1329,8 +1330,8 @@ async def down(
async def up(
self,
*,
- button: typing.Optional[Literal["left", "middle", "right"]] = None,
- click_count: typing.Optional[int] = None
+ button: Optional[Literal["left", "middle", "right"]] = None,
+ click_count: Optional[int] = None
) -> None:
"""Mouse.up
@@ -1340,7 +1341,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].
"""
@@ -1353,9 +1354,9 @@ async def click(
x: float,
y: float,
*,
- delay: typing.Optional[float] = None,
- button: typing.Optional[Literal["left", "middle", "right"]] = None,
- click_count: typing.Optional[int] = None
+ delay: Optional[float] = None,
+ button: Optional[Literal["left", "middle", "right"]] = None,
+ click_count: Optional[int] = None
) -> None:
"""Mouse.click
@@ -1365,11 +1366,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].
"""
@@ -1384,8 +1385,8 @@ async def dblclick(
x: float,
y: float,
*,
- delay: typing.Optional[float] = None,
- button: typing.Optional[Literal["left", "middle", "right"]] = None
+ delay: Optional[float] = None,
+ button: Optional[Literal["left", "middle", "right"]] = None
) -> None:
"""Mouse.dblclick
@@ -1396,7 +1397,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`.
@@ -1451,9 +1452,7 @@ async def tap(self, x: float, y: float) -> None:
class JSHandle(AsyncBase):
- async def evaluate(
- self, expression: str, arg: typing.Optional[typing.Any] = None
- ) -> typing.Any:
+ async def evaluate(self, expression: str, arg: Optional[Any] = None) -> Any:
"""JSHandle.evaluate
Returns the return value of `expression`.
@@ -1475,7 +1474,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
@@ -1490,7 +1489,7 @@ async def evaluate(
)
async def evaluate_handle(
- self, expression: str, arg: typing.Optional[typing.Any] = None
+ self, expression: str, arg: Optional[Any] = None
) -> "JSHandle":
"""JSHandle.evaluate_handle
@@ -1511,7 +1510,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
@@ -1544,7 +1543,7 @@ async def get_property(self, property_name: str) -> "JSHandle":
await self._impl_obj.get_property(propertyName=property_name)
)
- async def get_properties(self) -> typing.Dict[str, "JSHandle"]:
+ async def get_properties(self) -> Dict[str, "JSHandle"]:
"""JSHandle.get_properties
The method returns a map with **own property names** as keys and JSHandle instances for the property values.
@@ -1566,14 +1565,14 @@ async def get_properties(self) -> typing.Dict[str, "JSHandle"]:
return mapping.from_impl_dict(await self._impl_obj.get_properties())
- def as_element(self) -> typing.Optional["ElementHandle"]:
+ def as_element(self) -> Optional["ElementHandle"]:
"""JSHandle.as_element
Returns either `null` or the object handle itself, if the object handle is an instance of `ElementHandle`.
Returns
-------
- Union[ElementHandle, None]
+ Optional[ElementHandle]
"""
return mapping.from_impl_nullable(self._impl_obj.as_element())
@@ -1586,7 +1585,7 @@ async def dispose(self) -> None:
return mapping.from_maybe_impl(await self._impl_obj.dispose())
- async def json_value(self) -> typing.Any:
+ async def json_value(self) -> Any:
"""JSHandle.json_value
Returns a JSON representation of the object. If the object has a `toJSON` function, it **will not be called**.
@@ -1606,43 +1605,43 @@ async def json_value(self) -> typing.Any:
class ElementHandle(JSHandle):
- def as_element(self) -> typing.Optional["ElementHandle"]:
+ def as_element(self) -> Optional["ElementHandle"]:
"""ElementHandle.as_element
Returns either `null` or the object handle itself, if the object handle is an instance of `ElementHandle`.
Returns
-------
- Union[ElementHandle, None]
+ Optional[ElementHandle]
"""
return mapping.from_impl_nullable(self._impl_obj.as_element())
- async def owner_frame(self) -> typing.Optional["Frame"]:
+ async def owner_frame(self) -> Optional["Frame"]:
"""ElementHandle.owner_frame
Returns the frame containing the given element.
Returns
-------
- Union[Frame, None]
+ Optional[Frame]
"""
return mapping.from_impl_nullable(await self._impl_obj.owner_frame())
- async def content_frame(self) -> typing.Optional["Frame"]:
+ async def content_frame(self) -> Optional["Frame"]:
"""ElementHandle.content_frame
Returns the content frame for element handles referencing iframe nodes, or `null` otherwise
Returns
-------
- Union[Frame, None]
+ Optional[Frame]
"""
return mapping.from_impl_nullable(await self._impl_obj.content_frame())
- async def get_attribute(self, name: str) -> typing.Optional[str]:
+ async def get_attribute(self, name: str) -> Optional[str]:
"""ElementHandle.get_attribute
Returns element attribute value.
@@ -1654,19 +1653,19 @@ 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))
- async def text_content(self) -> typing.Optional[str]:
+ async def text_content(self) -> Optional[str]:
"""ElementHandle.text_content
Returns the `node.textContent`.
Returns
-------
- Union[str, None]
+ Optional[str]
"""
return mapping.from_maybe_impl(await self._impl_obj.text_content())
@@ -1768,7 +1767,7 @@ async def is_visible(self) -> bool:
return mapping.from_maybe_impl(await self._impl_obj.is_visible())
async def dispatch_event(
- self, type: str, event_init: typing.Optional[typing.Dict] = None
+ self, type: str, event_init: Optional[Dict] = None
) -> None:
"""ElementHandle.dispatch_event
@@ -1809,7 +1808,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.
"""
@@ -1820,7 +1819,7 @@ async def dispatch_event(
)
async def scroll_into_view_if_needed(
- self, *, timeout: typing.Optional[float] = None
+ self, *, timeout: Optional[float] = None
) -> None:
"""ElementHandle.scroll_into_view_if_needed
@@ -1833,7 +1832,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.
"""
@@ -1845,14 +1844,14 @@ async def scroll_into_view_if_needed(
async def hover(
self,
*,
- modifiers: typing.Optional[
- typing.Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
+ modifiers: Optional[
+ Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
] = None,
- position: typing.Optional[Position] = None,
- timeout: typing.Optional[float] = None,
- no_wait_after: typing.Optional[bool] = None,
- force: typing.Optional[bool] = None,
- trial: typing.Optional[bool] = None
+ position: Optional[Position] = None,
+ timeout: Optional[float] = None,
+ no_wait_after: Optional[bool] = None,
+ force: Optional[bool] = None,
+ trial: Optional[bool] = None
) -> None:
"""ElementHandle.hover
@@ -1875,16 +1874,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.
"""
@@ -1903,17 +1902,17 @@ async def hover(
async def click(
self,
*,
- modifiers: typing.Optional[
- typing.Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
+ modifiers: Optional[
+ Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
] = None,
- position: typing.Optional[Position] = None,
- delay: typing.Optional[float] = None,
- button: typing.Optional[Literal["left", "middle", "right"]] = None,
- click_count: typing.Optional[int] = None,
- timeout: typing.Optional[float] = None,
- force: typing.Optional[bool] = None,
- no_wait_after: typing.Optional[bool] = None,
- trial: typing.Optional[bool] = None
+ position: Optional[Position] = None,
+ delay: Optional[float] = None,
+ button: Optional[Literal["left", "middle", "right"]] = None,
+ click_count: Optional[int] = None,
+ timeout: Optional[float] = None,
+ force: Optional[bool] = None,
+ no_wait_after: Optional[bool] = None,
+ trial: Optional[bool] = None
) -> None:
"""ElementHandle.click
@@ -1936,22 +1935,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.
"""
@@ -1973,16 +1972,16 @@ async def click(
async def dblclick(
self,
*,
- modifiers: typing.Optional[
- typing.Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
+ modifiers: Optional[
+ Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
] = None,
- position: typing.Optional[Position] = None,
- delay: typing.Optional[float] = None,
- button: typing.Optional[Literal["left", "middle", "right"]] = None,
- timeout: typing.Optional[float] = None,
- force: typing.Optional[bool] = None,
- no_wait_after: typing.Optional[bool] = None,
- trial: typing.Optional[bool] = None
+ position: Optional[Position] = None,
+ delay: Optional[float] = None,
+ button: Optional[Literal["left", "middle", "right"]] = None,
+ timeout: Optional[float] = None,
+ force: Optional[bool] = None,
+ no_wait_after: Optional[bool] = None,
+ trial: Optional[bool] = None
) -> None:
"""ElementHandle.dblclick
@@ -2008,20 +2007,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.
"""
@@ -2041,17 +2040,15 @@ async def dblclick(
async def select_option(
self,
- value: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
+ value: Optional[Union[str, Sequence[str]]] = None,
*,
- index: typing.Optional[typing.Union[int, typing.Sequence[int]]] = None,
- label: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
- element: typing.Optional[
- typing.Union["ElementHandle", typing.Sequence["ElementHandle"]]
- ] = None,
- timeout: typing.Optional[float] = None,
- force: typing.Optional[bool] = None,
- no_wait_after: typing.Optional[bool] = None
- ) -> typing.List[str]:
+ index: Optional[Union[int, Sequence[int]]] = None,
+ label: Optional[Union[str, Sequence[str]]] = None,
+ element: Optional[Union["ElementHandle", Sequence["ElementHandle"]]] = None,
+ timeout: Optional[float] = None,
+ force: Optional[bool] = None,
+ no_wait_after: Optional[bool] = None
+ ) -> List[str]:
"""ElementHandle.select_option
This method waits for [actionability](https://playwright.dev/python/docs/actionability) checks, waits until all specified options are present in
@@ -2089,12 +2086,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`.
@@ -2119,14 +2116,14 @@ async def select_option(
async def tap(
self,
*,
- modifiers: typing.Optional[
- typing.Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
+ modifiers: Optional[
+ Sequence[Literal["Alt", "Control", "Meta", "Shift"]]
] = None,
- position: typing.Optional[Position] = None,
- timeout: typing.Optional[float] = None,
- force: typing.Optional[bool] = None,
- no_wait_after: typing.Optional[bool] = None,
- trial: typing.Optional[bool] = None
+ position: Optional[Position] = None,
+ timeout: Optional[float] = None,
+ force: Optional[bool] = None,
+ no_wait_after: Optional[bool] = None,
+ trial: Optional[bool] = None
) -> None:
"""ElementHandle.tap
@@ -2151,16 +2148,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.
"""
@@ -2180,9 +2177,9 @@ async def fill(
self,
value: str,
*,
- timeout: typing.Optional[float] = None,
- no_wait_after: typing.Optional[bool] = None,
- force: typing.Optional[bool] = None
+ timeout: Optional[float] = None,
+ no_wait_after: Optional[bool] = None,
+ force: Optional[bool] = None
) -> None:
"""ElementHandle.fill
@@ -2200,14 +2197,14 @@ async def fill(
----------
value : str
Value to set for the ``, `