Skip to content

docs: update generator to the new docs infra #414

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions playwright/_impl/_api_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
else: # pragma: no cover
from typing_extensions import Literal, TypedDict

# These are the structures that we like keeping in a JSON form for their potential reuse between SDKs / services.
# These are the structures that we like keeping in a JSON form for their potential
# reuse between SDKs / services. They are public and are a part of the
# stable API.

# Explicitly mark optional params as such for the documentation
# If there is at least one optional param, set total=False for better mypy handling.
Expand All @@ -32,7 +34,7 @@ class Cookie(TypedDict, total=False):
url: Optional[str]
domain: Optional[str]
path: Optional[str]
expires: Optional[int]
expires: Optional[float]
httpOnly: Optional[bool]
secure: Optional[bool]
sameSite: Optional[Literal["Strict", "Lax", "None"]]
Expand Down
29 changes: 16 additions & 13 deletions playwright/_impl/_api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
else: # pragma: no cover
from typing_extensions import TypedDict

# These are types that we use in the API. They are public and are a part of the
# stable API.


class Error(Exception):
def __init__(self, message: str, stack: str = None) -> None:
Expand Down Expand Up @@ -93,17 +96,17 @@ def __init__(self, latitude: float, longitude: float, accuracy: float = None):


class PdfMargins(ApiType):
top: Optional[Union[str, int]]
right: Optional[Union[str, int]]
bottom: Optional[Union[str, int]]
left: Optional[Union[str, int]]
top: Optional[Union[str, float]]
right: Optional[Union[str, float]]
bottom: Optional[Union[str, float]]
left: Optional[Union[str, float]]

def __init__(
self,
top: Union[str, int],
right: Union[str, int],
bottom: Union[str, int],
left: Union[str, int],
top: Union[str, float],
right: Union[str, float],
bottom: Union[str, float],
left: Union[str, float],
):
self.top = top
self.right = right
Expand Down Expand Up @@ -132,13 +135,13 @@ def __init__(

class SourceLocation(ApiType):
url: str
line: int
column: int
line_number: int
column_number: int

def __init__(self, url: str, line: int, column: int):
def __init__(self, url: str, line_number: int, column_number: int):
self.url = url
self.line = line
self.column = column
self.line_number = line_number
self.column_number = column_number


def filter_out_none(args: Dict) -> Any:
Expand Down
4 changes: 2 additions & 2 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def newContext(
extraHTTPHeaders: Dict[str, str] = None,
offline: bool = None,
httpCredentials: Tuple[str, str] = None,
deviceScaleFactor: int = None,
deviceScaleFactor: float = None,
isMobile: bool = None,
hasTouch: bool = None,
colorScheme: ColorScheme = None,
Expand Down Expand Up @@ -115,7 +115,7 @@ async def newPage(
extraHTTPHeaders: Dict[str, str] = None,
offline: bool = None,
httpCredentials: Tuple[str, str] = None,
deviceScaleFactor: int = None,
deviceScaleFactor: float = None,
isMobile: bool = None,
hasTouch: bool = None,
colorScheme: ColorScheme = None,
Expand Down
26 changes: 13 additions & 13 deletions playwright/_impl/_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ def _on_binding(self, binding_call: BindingCall) -> None:
return
asyncio.create_task(binding_call.call(func))

def setDefaultNavigationTimeout(self, timeout: int) -> None:
def setDefaultNavigationTimeout(self, timeout: float) -> None:
self._timeout_settings.set_navigation_timeout(timeout)
self._channel.send_no_reply(
"setDefaultNavigationTimeoutNoReply", dict(timeout=timeout)
)

def setDefaultTimeout(self, timeout: int) -> None:
def setDefaultTimeout(self, timeout: float) -> None:
self._timeout_settings.set_timeout(timeout)
self._channel.send_no_reply("setDefaultTimeoutNoReply", dict(timeout=timeout))

Expand Down Expand Up @@ -160,17 +160,17 @@ async def setOffline(self, offline: bool) -> None:
await self._channel.send("setOffline", dict(offline=offline))

async def addInitScript(
self, source: str = None, path: Union[str, Path] = None
self, script: str = None, path: Union[str, Path] = None
) -> None:
if path:
with open(path, "r") as file:
source = file.read()
if not isinstance(source, str):
script = file.read()
if not isinstance(script, str):
raise Error("Either path or source parameter must be specified")
await self._channel.send("addInitScript", dict(source=source))
await self._channel.send("addInitScript", dict(source=script))

async def exposeBinding(
self, name: str, binding: Callable, handle: bool = None
self, name: str, callback: Callable, handle: bool = None
) -> None:
for page in self._pages:
if name in page._bindings:
Expand All @@ -179,13 +179,13 @@ async def exposeBinding(
)
if name in self._bindings:
raise Error(f'Function "{name}" has been already registered')
self._bindings[name] = binding
self._bindings[name] = callback
await self._channel.send(
"exposeBinding", dict(name=name, needsHandle=handle or False)
)

async def exposeFunction(self, name: str, binding: Callable) -> None:
await self.exposeBinding(name, lambda source, *args: binding(*args))
async def exposeFunction(self, name: str, callback: Callable) -> None:
await self.exposeBinding(name, lambda source, *args: callback(*args))

async def route(self, url: URLMatch, handler: RouteHandler) -> None:
self._routes.append(RouteHandlerEntry(URLMatcher(url), handler))
Expand All @@ -209,7 +209,7 @@ async def unroute(
)

async def waitForEvent(
self, event: str, predicate: Callable[[Any], bool] = None, timeout: int = None
self, event: str, predicate: Callable[[Any], bool] = None, timeout: float = None
) -> Any:
if timeout is None:
timeout = self._timeout_settings.timeout()
Expand Down Expand Up @@ -256,13 +256,13 @@ def expect_event(
self,
event: str,
predicate: Callable[[Any], bool] = None,
timeout: int = None,
timeout: float = None,
) -> EventContextManagerImpl:
return EventContextManagerImpl(self.waitForEvent(event, predicate, timeout))

def expect_page(
self,
predicate: Callable[[Page], bool] = None,
timeout: int = None,
timeout: float = None,
) -> EventContextManagerImpl[Page]:
return EventContextManagerImpl(self.waitForEvent("page", predicate, timeout))
12 changes: 6 additions & 6 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ async def launch(
handleSIGINT: bool = None,
handleSIGTERM: bool = None,
handleSIGHUP: bool = None,
timeout: int = None,
timeout: float = None,
env: Env = None,
headless: bool = None,
devtools: bool = None,
proxy: ProxySettings = None,
downloadsPath: Union[str, Path] = None,
slowMo: int = None,
slowMo: float = None,
chromiumSandbox: bool = None,
firefoxUserPrefs: Dict[str, Union[str, int, bool]] = None,
firefoxUserPrefs: Dict[str, Union[str, float, bool]] = None,
) -> Browser:
params = locals_to_params(locals())
normalize_launch_params(params)
Expand All @@ -83,13 +83,13 @@ async def launchPersistentContext(
handleSIGINT: bool = None,
handleSIGTERM: bool = None,
handleSIGHUP: bool = None,
timeout: int = None,
timeout: float = None,
env: Env = None,
headless: bool = None,
devtools: bool = None,
proxy: ProxySettings = None,
downloadsPath: Union[str, Path] = None,
slowMo: int = None,
slowMo: float = None,
viewport: Union[Tuple[int, int], Literal[0]] = None,
ignoreHTTPSErrors: bool = None,
javaScriptEnabled: bool = None,
Expand All @@ -102,7 +102,7 @@ async def launchPersistentContext(
extraHTTPHeaders: Dict[str, str] = None,
offline: bool = None,
httpCredentials: Tuple[str, str] = None,
deviceScaleFactor: int = None,
deviceScaleFactor: float = None,
isMobile: bool = None,
hasTouch: bool = None,
colorScheme: ColorScheme = None,
Expand Down
45 changes: 23 additions & 22 deletions playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ def __init__(
async def _createSelectorForTest(self, name: str) -> Optional[str]:
return await self._channel.send("createSelectorForTest", dict(name=name))

def toString(self) -> str:
return self._preview

def asElement(self) -> Optional["ElementHandle"]:
return self

Expand All @@ -85,14 +82,14 @@ async def dispatchEvent(self, type: str, eventInit: Dict = None) -> None:
"dispatchEvent", dict(type=type, eventInit=serialize_argument(eventInit))
)

async def scrollIntoViewIfNeeded(self, timeout: int = None) -> None:
async def scrollIntoViewIfNeeded(self, timeout: float = None) -> None:
await self._channel.send("scrollIntoViewIfNeeded", locals_to_params(locals()))

async def hover(
self,
modifiers: List[KeyboardModifier] = None,
position: Tuple[float, float] = None,
timeout: int = None,
timeout: float = None,
force: bool = None,
) -> None:
await self._channel.send("hover", locals_to_params(locals()))
Expand All @@ -101,10 +98,10 @@ async def click(
self,
modifiers: List[KeyboardModifier] = None,
position: Tuple[float, float] = None,
delay: int = None,
delay: float = None,
button: MouseButton = None,
clickCount: int = None,
timeout: int = None,
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
) -> None:
Expand All @@ -114,9 +111,9 @@ async def dblclick(
self,
modifiers: List[KeyboardModifier] = None,
position: Tuple[float, float] = None,
delay: int = None,
delay: float = None,
button: MouseButton = None,
timeout: int = None,
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
) -> None:
Expand All @@ -128,7 +125,7 @@ async def selectOption(
index: Union[int, List[int]] = None,
label: Union[str, List[str]] = None,
element: Union["ElementHandle", List["ElementHandle"]] = None,
timeout: int = None,
timeout: float = None,
noWaitAfter: bool = None,
) -> List[str]:
params = locals_to_params(
Expand All @@ -144,24 +141,24 @@ async def tap(
self,
modifiers: List[KeyboardModifier] = None,
position: Tuple[float, float] = None,
timeout: int = None,
timeout: float = None,
force: bool = None,
noWaitAfter: bool = None,
) -> None:
await self._channel.send("tap", locals_to_params(locals()))

async def fill(
self, value: str, timeout: int = None, noWaitAfter: bool = None
self, value: str, timeout: float = None, noWaitAfter: bool = None
) -> None:
await self._channel.send("fill", locals_to_params(locals()))

async def selectText(self, timeout: int = None) -> None:
async def selectText(self, timeout: float = None) -> None:
await self._channel.send("selectText", locals_to_params(locals()))

async def setInputFiles(
self,
files: Union[str, Path, FilePayload, List[str], List[Path], List[FilePayload]],
timeout: int = None,
timeout: float = None,
noWaitAfter: bool = None,
) -> None:
params = locals_to_params(locals())
Expand All @@ -174,24 +171,28 @@ async def focus(self) -> None:
async def type(
self,
text: str,
delay: int = None,
timeout: int = None,
delay: float = None,
timeout: float = None,
noWaitAfter: bool = None,
) -> None:
await self._channel.send("type", locals_to_params(locals()))

async def press(
self, key: str, delay: int = None, timeout: int = None, noWaitAfter: bool = None
self,
key: str,
delay: float = None,
timeout: float = None,
noWaitAfter: bool = None,
) -> None:
await self._channel.send("press", locals_to_params(locals()))

async def check(
self, timeout: int = None, force: bool = None, noWaitAfter: bool = None
self, timeout: float = None, force: bool = None, noWaitAfter: bool = None
) -> None:
await self._channel.send("check", locals_to_params(locals()))

async def uncheck(
self, timeout: int = None, force: bool = None, noWaitAfter: bool = None
self, timeout: float = None, force: bool = None, noWaitAfter: bool = None
) -> None:
await self._channel.send("uncheck", locals_to_params(locals()))

Expand All @@ -201,7 +202,7 @@ async def boundingBox(self) -> Optional[FloatRect]:

async def screenshot(
self,
timeout: int = None,
timeout: float = None,
type: Literal["jpeg", "png"] = None,
path: Union[str, Path] = None,
quality: int = None,
Expand Down Expand Up @@ -271,15 +272,15 @@ async def evalOnSelectorAll(
async def waitForElementState(
self,
state: Literal["disabled", "enabled", "hidden", "stable", "visible"],
timeout: int = None,
timeout: float = None,
) -> None:
await self._channel.send("waitForElementState", locals_to_params(locals()))

async def waitForSelector(
self,
selector: str,
state: Literal["attached", "detached", "hidden", "visible"] = None,
timeout: int = None,
timeout: float = None,
) -> Optional["ElementHandle"]:
return from_nullable_channel(
await self._channel.send("waitForSelector", locals_to_params(locals()))
Expand Down
2 changes: 1 addition & 1 deletion playwright/_impl/_file_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def isMultiple(self) -> bool:
async def setFiles(
self,
files: Union[str, FilePayload, List[str], List[FilePayload]],
timeout: int = None,
timeout: float = None,
noWaitAfter: bool = None,
) -> None:
await self._element_handle.setInputFiles(files, timeout, noWaitAfter)
Expand Down
Loading