Skip to content

Commit 39374d0

Browse files
authored
docstrings: only render async/sync dialect snippets (microsoft#426)
1 parent fb9a258 commit 39374d0

File tree

5 files changed

+28
-79
lines changed

5 files changed

+28
-79
lines changed

playwright/async_api/_generated.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -664,18 +664,12 @@ def expect_event(
664664
`predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is
665665
closed before the `event` is fired.
666666
667-
```python async
667+
```py
668668
async with ws.expect_event(event_name) as event_info:
669669
await ws.click("button")
670670
value = await event_info.value
671671
```
672672
673-
```python sync
674-
with ws.expect_event(event_name) as event_info:
675-
ws.click("button")
676-
value = event_info.value
677-
```
678-
679673
Parameters
680674
----------
681675
event : str
@@ -4597,18 +4591,12 @@ def expect_navigation(
45974591
cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
45984592
Consider this example:
45994593
4600-
```python async
4594+
```py
46014595
async with frame.expect_navigation():
46024596
await frame.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
46034597
# Context manager waited for the navigation to happen.
46044598
```
46054599
4606-
```python sync
4607-
with frame.expect_navigation():
4608-
frame.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
4609-
# Context manager waited for the navigation to happen.
4610-
```
4611-
46124600
> NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
46134601
considered a navigation.
46144602
@@ -7890,18 +7878,12 @@ def expect_event(
78907878
`predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
78917879
closed before the `event` is fired.
78927880
7893-
```python async
7881+
```py
78947882
async with page.expect_event(event_name) as event_info:
78957883
await page.click("button")
78967884
value = await event_info.value
78977885
```
78987886
7899-
```python sync
7900-
with page.expect_event(event_name) as event_info:
7901-
page.click("button")
7902-
value = event_info.value
7903-
```
7904-
79057887
Parameters
79067888
----------
79077889
event : str
@@ -8024,18 +8006,12 @@ def expect_navigation(
80248006
cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
80258007
Consider this example:
80268008
8027-
```python async
8009+
```py
80288010
async with page.expect_navigation():
80298011
await page.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
80308012
# Context manager waited for the navigation to happen.
80318013
```
80328014
8033-
```python sync
8034-
with page.expect_navigation():
8035-
page.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
8036-
# Context manager waited for the navigation to happen.
8037-
```
8038-
80398015
> NOTE: Usage of the [History API](https://developer.mozilla.org/en-US/docs/Web/API/History_API) to change the URL is
80408016
considered a navigation.
80418017
@@ -8770,18 +8746,12 @@ def expect_event(
87708746
`predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if browser context
87718747
is closed before the `event` is fired.
87728748
8773-
```python async
8749+
```py
87748750
async with context.expect_event("page") as event_info:
87758751
await context.click("button")
87768752
page = await event_info.value
87778753
```
87788754
8779-
```python sync
8780-
with context.expect_event("page") as event_info:
8781-
context.click("button")
8782-
page = event_info.value
8783-
```
8784-
87858755
Parameters
87868756
----------
87878757
event : str

playwright/sync_api/_generated.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -670,13 +670,7 @@ def expect_event(
670670
`predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the socket is
671671
closed before the `event` is fired.
672672
673-
```python async
674-
async with ws.expect_event(event_name) as event_info:
675-
await ws.click("button")
676-
value = await event_info.value
677-
```
678-
679-
```python sync
673+
```py
680674
with ws.expect_event(event_name) as event_info:
681675
ws.click("button")
682676
value = event_info.value
@@ -4720,13 +4714,7 @@ def expect_navigation(
47204714
cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
47214715
Consider this example:
47224716
4723-
```python async
4724-
async with frame.expect_navigation():
4725-
await frame.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
4726-
# Context manager waited for the navigation to happen.
4727-
```
4728-
4729-
```python sync
4717+
```py
47304718
with frame.expect_navigation():
47314719
frame.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
47324720
# Context manager waited for the navigation to happen.
@@ -8117,13 +8105,7 @@ def expect_event(
81178105
`predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if the page is
81188106
closed before the `event` is fired.
81198107
8120-
```python async
8121-
async with page.expect_event(event_name) as event_info:
8122-
await page.click("button")
8123-
value = await event_info.value
8124-
```
8125-
8126-
```python sync
8108+
```py
81278109
with page.expect_event(event_name) as event_info:
81288110
page.click("button")
81298111
value = event_info.value
@@ -8247,13 +8229,7 @@ def expect_navigation(
82478229
cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation from a `setTimeout`.
82488230
Consider this example:
82498231
8250-
```python async
8251-
async with page.expect_navigation():
8252-
await page.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
8253-
# Context manager waited for the navigation to happen.
8254-
```
8255-
8256-
```python sync
8232+
```py
82578233
with page.expect_navigation():
82588234
page.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
82598235
# Context manager waited for the navigation to happen.
@@ -9008,13 +8984,7 @@ def expect_event(
90088984
`predicate` function and waits for `predicate(event)` to return a truthy value. Will throw an error if browser context
90098985
is closed before the `event` is fired.
90108986
9011-
```python async
9012-
async with context.expect_event("page") as event_info:
9013-
await context.click("button")
9014-
page = await event_info.value
9015-
```
9016-
9017-
```python sync
8987+
```py
90188988
with context.expect_event("page") as event_info:
90198989
context.click("button")
90208990
page = event_info.value

scripts/documentation_provider.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434

3535

3636
class DocumentationProvider:
37-
def __init__(self) -> None:
37+
def __init__(self, is_async: bool) -> None:
38+
self.is_async = is_async
3839
self.api: Any = {}
3940
self.printed_entries: List[str] = []
4041
process_output = subprocess.run(
@@ -190,21 +191,29 @@ def indent_paragraph(self, p: str, indent: str) -> str:
190191
def beautify_method_comment(self, comment: str, indent: str) -> str:
191192
lines = comment.split("\n")
192193
result = []
193-
in_example = False
194+
skip_example = False
194195
last_was_blank = True
195196
for line in lines:
196197
if not line.strip():
197198
last_was_blank = True
198199
continue
199-
if line.strip() == "```js":
200-
in_example = True
201-
if not in_example:
200+
match = re.match(r"\s*```(.+)", line)
201+
if match:
202+
lang = match[1]
203+
if lang in ["html", "yml", "sh", "py", "python"]:
204+
skip_example = False
205+
elif lang == "python " + ("async" if self.is_async else "sync"):
206+
skip_example = False
207+
line = "```py"
208+
else:
209+
skip_example = True
210+
if not skip_example:
202211
if last_was_blank:
203212
last_was_blank = False
204213
result.append("")
205214
result.append(self.render_links(line))
206-
if line.strip() == "```":
207-
in_example = False
215+
if skip_example and line.strip() == "```":
216+
skip_example = False
208217
return self.indent_paragraph("\n".join(result), indent)
209218

210219
def render_links(self, comment: str) -> str:

scripts/generate_async_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
signature,
3333
)
3434

35-
documentation_provider = DocumentationProvider()
35+
documentation_provider = DocumentationProvider(True)
3636

3737

3838
def generate(t: Any) -> None:

scripts/generate_sync_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
signature,
3333
)
3434

35-
documentation_provider = DocumentationProvider()
35+
documentation_provider = DocumentationProvider(False)
3636

3737

3838
def generate(t: Any) -> None:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy