Skip to content

Commit e2e93b5

Browse files
authored
chore: make internal methods snake case (microsoft#417)
1 parent 8daba92 commit e2e93b5

23 files changed

+602
-568
lines changed

playwright/_impl/_browser.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ def _on_close(self) -> None:
6161
def contexts(self) -> List[BrowserContext]:
6262
return self._contexts.copy()
6363

64-
def isConnected(self) -> bool:
64+
def is_connected(self) -> bool:
6565
return self._is_connected
6666

67-
async def newContext(
67+
async def new_context(
6868
self,
6969
viewport: Union[Tuple[int, int], Literal[0]] = None,
7070
ignoreHTTPSErrors: bool = None,
@@ -101,7 +101,7 @@ async def newContext(
101101
context._options = params
102102
return context
103103

104-
async def newPage(
104+
async def new_page(
105105
self,
106106
viewport: Union[Tuple[int, int], Literal[0]] = None,
107107
ignoreHTTPSErrors: bool = None,
@@ -129,8 +129,8 @@ async def newPage(
129129
storageState: Union[StorageState, str, Path] = None,
130130
) -> Page:
131131
params = locals_to_params(locals())
132-
context = await self.newContext(**params)
133-
page = await context.newPage()
132+
context = await self.new_context(**params)
133+
page = await context.new_page()
134134
page._owned_context = context
135135
context._owner_page = page
136136
return page

playwright/_impl/_browser_context.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ def _on_binding(self, binding_call: BindingCall) -> None:
9797
return
9898
asyncio.create_task(binding_call.call(func))
9999

100-
def setDefaultNavigationTimeout(self, timeout: float) -> None:
100+
def set_default_navigation_timeout(self, timeout: float) -> None:
101101
self._timeout_settings.set_navigation_timeout(timeout)
102102
self._channel.send_no_reply(
103103
"setDefaultNavigationTimeoutNoReply", dict(timeout=timeout)
104104
)
105105

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

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

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

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

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

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

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

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

144-
async def setGeolocation(
144+
async def set_geolocation(
145145
self, latitude: float, longitude: float, accuracy: Optional[float]
146146
) -> None:
147147
await self._channel.send(
148148
"setGeolocation", {"geolocation": locals_to_params(locals())}
149149
)
150150

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

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

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

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

172-
async def exposeBinding(
172+
async def expose_binding(
173173
self, name: str, callback: Callable, handle: bool = None
174174
) -> None:
175175
for page in self._pages:
@@ -184,8 +184,8 @@ async def exposeBinding(
184184
"exposeBinding", dict(name=name, needsHandle=handle or False)
185185
)
186186

187-
async def exposeFunction(self, name: str, callback: Callable) -> None:
188-
await self.exposeBinding(name, lambda source, *args: callback(*args))
187+
async def expose_function(self, name: str, callback: Callable) -> None:
188+
await self.expose_binding(name, lambda source, *args: callback(*args))
189189

190190
async def route(self, url: URLMatch, handler: RouteHandler) -> None:
191191
self._routes.append(RouteHandlerEntry(URLMatcher(url), handler))
@@ -208,7 +208,7 @@ async def unroute(
208208
"setNetworkInterceptionEnabled", dict(enabled=False)
209209
)
210210

211-
async def waitForEvent(
211+
async def wait_for_event(
212212
self, event: str, predicate: Callable[[Any], bool] = None, timeout: float = None
213213
) -> Any:
214214
if timeout is None:
@@ -245,7 +245,7 @@ async def close(self) -> None:
245245
if not is_safe_close_error(e):
246246
raise e
247247

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

263263
def expect_page(
264264
self,
265265
predicate: Callable[[Page], bool] = None,
266266
timeout: float = None,
267267
) -> EventContextManagerImpl[Page]:
268-
return EventContextManagerImpl(self.waitForEvent("page", predicate, timeout))
268+
return EventContextManagerImpl(self.wait_for_event("page", predicate, timeout))

playwright/_impl/_browser_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def name(self) -> str:
4444
return self._initializer["name"]
4545

4646
@property
47-
def executablePath(self) -> str:
47+
def executable_path(self) -> str:
4848
return self._initializer["executablePath"]
4949

5050
async def launch(
@@ -74,7 +74,7 @@ async def launch(
7474
raise not_installed_error(f'"{self.name}" browser was not found.')
7575
raise e
7676

77-
async def launchPersistentContext(
77+
async def launch_persistent_context(
7878
self,
7979
userDataDir: Union[str, Path],
8080
executablePath: Union[str, Path] = None,

playwright/_impl/_chromium_browser_context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def _on_service_worker(self, worker: Worker) -> None:
5555
self._service_workers.add(worker)
5656
self.emit(ChromiumBrowserContext.Events.ServiceWorker, worker)
5757

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

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

64-
async def newCDPSession(self, page: Page) -> CDPSession:
64+
async def new_cdp_session(self, page: Page) -> CDPSession:
6565
return from_channel(
6666
await self._channel.send("crNewCDPSession", {"page": page._channel})
6767
)

playwright/_impl/_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def message(self) -> str:
3333
return self._initializer["message"]
3434

3535
@property
36-
def defaultValue(self) -> str:
36+
def default_value(self) -> str:
3737
return self._initializer["defaultValue"]
3838

3939
async def accept(self, promptText: str = None) -> None:

playwright/_impl/_download.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def url(self) -> str:
3030
return self._initializer["url"]
3131

3232
@property
33-
def suggestedFilename(self) -> str:
33+
def suggested_filename(self) -> str:
3434
return self._initializer["suggestedFilename"]
3535

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

45-
async def saveAs(self, path: Union[str, Path]) -> None:
45+
async def save_as(self, path: Union[str, Path]) -> None:
4646
path = str(Path(path))
4747
return await self._channel.send("saveAs", dict(path=path))

playwright/_impl/_element_handle.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,33 @@ def __init__(
5656
async def _createSelectorForTest(self, name: str) -> Optional[str]:
5757
return await self._channel.send("createSelectorForTest", dict(name=name))
5858

59-
def asElement(self) -> Optional["ElementHandle"]:
59+
def as_element(self) -> Optional["ElementHandle"]:
6060
return self
6161

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

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

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

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

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

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

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

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

8888
async def hover(
@@ -119,7 +119,7 @@ async def dblclick(
119119
) -> None:
120120
await self._channel.send("dblclick", locals_to_params(locals()))
121121

122-
async def selectOption(
122+
async def select_option(
123123
self,
124124
value: Union[str, List[str]] = None,
125125
index: Union[int, List[int]] = None,
@@ -152,10 +152,10 @@ async def fill(
152152
) -> None:
153153
await self._channel.send("fill", locals_to_params(locals()))
154154

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

158-
async def setInputFiles(
158+
async def set_input_files(
159159
self,
160160
files: Union[str, Path, FilePayload, List[str], List[Path], List[FilePayload]],
161161
timeout: float = None,
@@ -196,7 +196,7 @@ async def uncheck(
196196
) -> None:
197197
await self._channel.send("uncheck", locals_to_params(locals()))
198198

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

@@ -218,20 +218,20 @@ async def screenshot(
218218
fd.write(decoded_binary)
219219
return decoded_binary
220220

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

226-
async def querySelectorAll(self, selector: str) -> List["ElementHandle"]:
226+
async def query_selector_all(self, selector: str) -> List["ElementHandle"]:
227227
return list(
228228
map(
229229
cast(Callable[[Any], Any], from_nullable_channel),
230230
await self._channel.send("querySelectorAll", dict(selector=selector)),
231231
)
232232
)
233233

234-
async def evalOnSelector(
234+
async def eval_on_selector(
235235
self,
236236
selector: str,
237237
expression: str,
@@ -250,7 +250,7 @@ async def evalOnSelector(
250250
)
251251
)
252252

253-
async def evalOnSelectorAll(
253+
async def eval_on_selector_all(
254254
self,
255255
selector: str,
256256
expression: str,
@@ -269,14 +269,14 @@ async def evalOnSelectorAll(
269269
)
270270
)
271271

272-
async def waitForElementState(
272+
async def wait_for_element_state(
273273
self,
274274
state: Literal["disabled", "enabled", "hidden", "stable", "visible"],
275275
timeout: float = None,
276276
) -> None:
277277
await self._channel.send("waitForElementState", locals_to_params(locals()))
278278

279-
async def waitForSelector(
279+
async def wait_for_selector(
280280
self,
281281
selector: str,
282282
state: Literal["attached", "detached", "hidden", "visible"] = None,

playwright/_impl/_file_chooser.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@ def element(self) -> "ElementHandle":
4444
return self._element_handle
4545

4646
@property
47-
def isMultiple(self) -> bool:
47+
def is_multiple(self) -> bool:
4848
return self._is_multiple
4949

50-
async def setFiles(
50+
async def set_files(
5151
self,
5252
files: Union[str, FilePayload, List[str], List[FilePayload]],
5353
timeout: float = None,
5454
noWaitAfter: bool = None,
5555
) -> None:
56-
await self._element_handle.setInputFiles(files, timeout, noWaitAfter)
56+
await self._element_handle.set_input_files(files, timeout, noWaitAfter)
5757

5858

5959
def normalize_file_payloads(

0 commit comments

Comments
 (0)