Skip to content

chore: make internal methods snake case #417

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 7, 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
10 changes: 5 additions & 5 deletions playwright/_impl/_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def _on_close(self) -> None:
def contexts(self) -> List[BrowserContext]:
return self._contexts.copy()

def isConnected(self) -> bool:
def is_connected(self) -> bool:
return self._is_connected

async def newContext(
async def new_context(
self,
viewport: Union[Tuple[int, int], Literal[0]] = None,
ignoreHTTPSErrors: bool = None,
Expand Down Expand Up @@ -101,7 +101,7 @@ async def newContext(
context._options = params
return context

async def newPage(
async def new_page(
self,
viewport: Union[Tuple[int, int], Literal[0]] = None,
ignoreHTTPSErrors: bool = None,
Expand Down Expand Up @@ -129,8 +129,8 @@ async def newPage(
storageState: Union[StorageState, str, Path] = None,
) -> Page:
params = locals_to_params(locals())
context = await self.newContext(**params)
page = await context.newPage()
context = await self.new_context(**params)
page = await context.new_page()
page._owned_context = context
context._owner_page = page
return page
Expand Down
40 changes: 20 additions & 20 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: float) -> None:
def set_default_navigation_timeout(self, timeout: float) -> None:
self._timeout_settings.set_navigation_timeout(timeout)
self._channel.send_no_reply(
"setDefaultNavigationTimeoutNoReply", dict(timeout=timeout)
)

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

Expand All @@ -115,9 +115,9 @@ def pages(self) -> List[Page]:
def browser(self) -> Optional["Browser"]:
return self._browser

async def newPage(self) -> Page:
async def new_page(self) -> Page:
if self._owner_page:
raise Error("Please use browser.newContext()")
raise Error("Please use browser.new_context()")
return from_channel(await self._channel.send("newPage"))

async def cookies(self, urls: Union[str, List[str]] = None) -> List[Cookie]:
Expand All @@ -127,39 +127,39 @@ async def cookies(self, urls: Union[str, List[str]] = None) -> List[Cookie]:
urls = [urls]
return await self._channel.send("cookies", dict(urls=urls))

async def addCookies(self, cookies: List[Cookie]) -> None:
async def add_cookies(self, cookies: List[Cookie]) -> None:
await self._channel.send("addCookies", dict(cookies=cookies))

async def clearCookies(self) -> None:
async def clear_cookies(self) -> None:
await self._channel.send("clearCookies")

async def grantPermissions(
async def grant_permissions(
self, permissions: List[str], origin: str = None
) -> None:
await self._channel.send("grantPermissions", locals_to_params(locals()))

async def clearPermissions(self) -> None:
async def clear_permissions(self) -> None:
await self._channel.send("clearPermissions")

async def setGeolocation(
async def set_geolocation(
self, latitude: float, longitude: float, accuracy: Optional[float]
) -> None:
await self._channel.send(
"setGeolocation", {"geolocation": locals_to_params(locals())}
)

async def resetGeolocation(self) -> None:
async def reset_geolocation(self) -> None:
await self._channel.send("setGeolocation", {})

async def setExtraHTTPHeaders(self, headers: Dict[str, str]) -> None:
async def set_extra_http_headers(self, headers: Dict[str, str]) -> None:
await self._channel.send(
"setExtraHTTPHeaders", dict(headers=serialize_headers(headers))
)

async def setOffline(self, offline: bool) -> None:
async def set_offline(self, offline: bool) -> None:
await self._channel.send("setOffline", dict(offline=offline))

async def addInitScript(
async def add_init_script(
self, script: str = None, path: Union[str, Path] = None
) -> None:
if path:
Expand All @@ -169,7 +169,7 @@ async def addInitScript(
raise Error("Either path or source parameter must be specified")
await self._channel.send("addInitScript", dict(source=script))

async def exposeBinding(
async def expose_binding(
self, name: str, callback: Callable, handle: bool = None
) -> None:
for page in self._pages:
Expand All @@ -184,8 +184,8 @@ async def exposeBinding(
"exposeBinding", dict(name=name, needsHandle=handle or False)
)

async def exposeFunction(self, name: str, callback: Callable) -> None:
await self.exposeBinding(name, lambda source, *args: callback(*args))
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: RouteHandler) -> None:
self._routes.append(RouteHandlerEntry(URLMatcher(url), handler))
Expand All @@ -208,7 +208,7 @@ async def unroute(
"setNetworkInterceptionEnabled", dict(enabled=False)
)

async def waitForEvent(
async def wait_for_event(
self, event: str, predicate: Callable[[Any], bool] = None, timeout: float = None
) -> Any:
if timeout is None:
Expand Down Expand Up @@ -245,7 +245,7 @@ async def close(self) -> None:
if not is_safe_close_error(e):
raise e

async def storageState(self, path: Union[str, Path] = None) -> StorageState:
async def storage_state(self, path: Union[str, Path] = None) -> StorageState:
result = await self._channel.send_return_as_dict("storageState")
if path:
with open(path, "w") as f:
Expand All @@ -258,11 +258,11 @@ def expect_event(
predicate: Callable[[Any], bool] = None,
timeout: float = None,
) -> EventContextManagerImpl:
return EventContextManagerImpl(self.waitForEvent(event, predicate, timeout))
return EventContextManagerImpl(self.wait_for_event(event, predicate, timeout))

def expect_page(
self,
predicate: Callable[[Page], bool] = None,
timeout: float = None,
) -> EventContextManagerImpl[Page]:
return EventContextManagerImpl(self.waitForEvent("page", predicate, timeout))
return EventContextManagerImpl(self.wait_for_event("page", predicate, timeout))
4 changes: 2 additions & 2 deletions playwright/_impl/_browser_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def name(self) -> str:
return self._initializer["name"]

@property
def executablePath(self) -> str:
def executable_path(self) -> str:
return self._initializer["executablePath"]

async def launch(
Expand Down Expand Up @@ -74,7 +74,7 @@ async def launch(
raise not_installed_error(f'"{self.name}" browser was not found.')
raise e

async def launchPersistentContext(
async def launch_persistent_context(
self,
userDataDir: Union[str, Path],
executablePath: Union[str, Path] = None,
Expand Down
6 changes: 3 additions & 3 deletions playwright/_impl/_chromium_browser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def _on_service_worker(self, worker: Worker) -> None:
self._service_workers.add(worker)
self.emit(ChromiumBrowserContext.Events.ServiceWorker, worker)

def backgroundPages(self) -> List[Page]:
def background_pages(self) -> List[Page]:
return list(self._background_pages)

def serviceWorkers(self) -> List[Worker]:
def service_workers(self) -> List[Worker]:
return list(self._service_workers)

async def newCDPSession(self, page: Page) -> CDPSession:
async def new_cdp_session(self, page: Page) -> CDPSession:
return from_channel(
await self._channel.send("crNewCDPSession", {"page": page._channel})
)
2 changes: 1 addition & 1 deletion playwright/_impl/_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def message(self) -> str:
return self._initializer["message"]

@property
def defaultValue(self) -> str:
def default_value(self) -> str:
return self._initializer["defaultValue"]

async def accept(self, promptText: str = None) -> None:
Expand Down
4 changes: 2 additions & 2 deletions playwright/_impl/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def url(self) -> str:
return self._initializer["url"]

@property
def suggestedFilename(self) -> str:
def suggested_filename(self) -> str:
return self._initializer["suggestedFilename"]

async def delete(self) -> None:
Expand All @@ -42,6 +42,6 @@ async def failure(self) -> Optional[str]:
async def path(self) -> Optional[str]:
return await self._channel.send("path")

async def saveAs(self, path: Union[str, Path]) -> None:
async def save_as(self, path: Union[str, Path]) -> None:
path = str(Path(path))
return await self._channel.send("saveAs", dict(path=path))
38 changes: 19 additions & 19 deletions playwright/_impl/_element_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,33 +56,33 @@ def __init__(
async def _createSelectorForTest(self, name: str) -> Optional[str]:
return await self._channel.send("createSelectorForTest", dict(name=name))

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

async def ownerFrame(self) -> Optional["Frame"]:
async def owner_frame(self) -> Optional["Frame"]:
return from_nullable_channel(await self._channel.send("ownerFrame"))

async def contentFrame(self) -> Optional["Frame"]:
async def content_frame(self) -> Optional["Frame"]:
return from_nullable_channel(await self._channel.send("contentFrame"))

async def getAttribute(self, name: str) -> Optional[str]:
async def get_attribute(self, name: str) -> Optional[str]:
return await self._channel.send("getAttribute", dict(name=name))

async def textContent(self) -> Optional[str]:
async def text_content(self) -> Optional[str]:
return await self._channel.send("textContent")

async def innerText(self) -> str:
async def inner_text(self) -> str:
return await self._channel.send("innerText")

async def innerHTML(self) -> str:
async def inner_html(self) -> str:
return await self._channel.send("innerHTML")

async def dispatchEvent(self, type: str, eventInit: Dict = None) -> None:
async def dispatch_event(self, type: str, eventInit: Dict = None) -> None:
await self._channel.send(
"dispatchEvent", dict(type=type, eventInit=serialize_argument(eventInit))
)

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

async def hover(
Expand Down Expand Up @@ -119,7 +119,7 @@ async def dblclick(
) -> None:
await self._channel.send("dblclick", locals_to_params(locals()))

async def selectOption(
async def select_option(
self,
value: Union[str, List[str]] = None,
index: Union[int, List[int]] = None,
Expand Down Expand Up @@ -152,10 +152,10 @@ async def fill(
) -> None:
await self._channel.send("fill", locals_to_params(locals()))

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

async def setInputFiles(
async def set_input_files(
self,
files: Union[str, Path, FilePayload, List[str], List[Path], List[FilePayload]],
timeout: float = None,
Expand Down Expand Up @@ -196,7 +196,7 @@ async def uncheck(
) -> None:
await self._channel.send("uncheck", locals_to_params(locals()))

async def boundingBox(self) -> Optional[FloatRect]:
async def bounding_box(self) -> Optional[FloatRect]:
bb = await self._channel.send("boundingBox")
return FloatRect._parse(bb)

Expand All @@ -218,20 +218,20 @@ async def screenshot(
fd.write(decoded_binary)
return decoded_binary

async def querySelector(self, selector: str) -> Optional["ElementHandle"]:
async def query_selector(self, selector: str) -> Optional["ElementHandle"]:
return from_nullable_channel(
await self._channel.send("querySelector", dict(selector=selector))
)

async def querySelectorAll(self, selector: str) -> List["ElementHandle"]:
async def query_selector_all(self, selector: str) -> List["ElementHandle"]:
return list(
map(
cast(Callable[[Any], Any], from_nullable_channel),
await self._channel.send("querySelectorAll", dict(selector=selector)),
)
)

async def evalOnSelector(
async def eval_on_selector(
self,
selector: str,
expression: str,
Expand All @@ -250,7 +250,7 @@ async def evalOnSelector(
)
)

async def evalOnSelectorAll(
async def eval_on_selector_all(
self,
selector: str,
expression: str,
Expand All @@ -269,14 +269,14 @@ async def evalOnSelectorAll(
)
)

async def waitForElementState(
async def wait_for_element_state(
self,
state: Literal["disabled", "enabled", "hidden", "stable", "visible"],
timeout: float = None,
) -> None:
await self._channel.send("waitForElementState", locals_to_params(locals()))

async def waitForSelector(
async def wait_for_selector(
self,
selector: str,
state: Literal["attached", "detached", "hidden", "visible"] = None,
Expand Down
6 changes: 3 additions & 3 deletions playwright/_impl/_file_chooser.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ def element(self) -> "ElementHandle":
return self._element_handle

@property
def isMultiple(self) -> bool:
def is_multiple(self) -> bool:
return self._is_multiple

async def setFiles(
async def set_files(
self,
files: Union[str, FilePayload, List[str], List[FilePayload]],
timeout: float = None,
noWaitAfter: bool = None,
) -> None:
await self._element_handle.setInputFiles(files, timeout, noWaitAfter)
await self._element_handle.set_input_files(files, timeout, noWaitAfter)


def normalize_file_payloads(
Expand Down
Loading