mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
docs: add types to Python run() defs (#27044)
Fixes https://github.com/microsoft/playwright-python/issues/2071
This commit is contained in:
parent
00b74a4aae
commit
5faa66912c
@ -33,9 +33,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
firefox = playwright.firefox
|
||||
browser = await firefox.launch()
|
||||
page = await browser.new_page()
|
||||
@ -49,9 +49,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
firefox = playwright.firefox
|
||||
browser = firefox.launch()
|
||||
page = browser.new_page()
|
||||
|
@ -589,9 +589,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = await webkit.launch(headless=false)
|
||||
context = await browser.new_context()
|
||||
@ -615,9 +615,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = webkit.launch(headless=false)
|
||||
context = browser.new_context()
|
||||
@ -833,15 +833,15 @@ public class Example {
|
||||
```python async
|
||||
import asyncio
|
||||
import hashlib
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
def sha256(text):
|
||||
def sha256(text: str) -> str:
|
||||
m = hashlib.sha256()
|
||||
m.update(bytes(text, "utf8"))
|
||||
return m.hexdigest()
|
||||
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = await webkit.launch(headless=False)
|
||||
context = await browser.new_context()
|
||||
@ -868,13 +868,13 @@ asyncio.run(main())
|
||||
import hashlib
|
||||
from playwright.sync_api import sync_playwright
|
||||
|
||||
def sha256(text):
|
||||
def sha256(text: str) -> str:
|
||||
m = hashlib.sha256()
|
||||
m.update(bytes(text, "utf8"))
|
||||
return m.hexdigest()
|
||||
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = webkit.launch(headless=False)
|
||||
context = browser.new_context()
|
||||
|
@ -35,9 +35,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = await chromium.launch()
|
||||
page = await browser.new_page()
|
||||
@ -52,9 +52,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = chromium.launch()
|
||||
page = browser.new_page()
|
||||
|
@ -42,13 +42,13 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def handle_dialog(dialog):
|
||||
print(dialog.message)
|
||||
await dialog.dismiss()
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = await chromium.launch()
|
||||
page = await browser.new_page()
|
||||
@ -63,13 +63,13 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def handle_dialog(dialog):
|
||||
print(dialog.message)
|
||||
dialog.dismiss()
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = chromium.launch()
|
||||
page = browser.new_page()
|
||||
|
@ -56,9 +56,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
firefox = playwright.firefox
|
||||
browser = await firefox.launch()
|
||||
page = await browser.new_page()
|
||||
@ -78,9 +78,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
firefox = playwright.firefox
|
||||
browser = firefox.launch()
|
||||
page = browser.new_page()
|
||||
@ -1860,9 +1860,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = await webkit.launch()
|
||||
page = await browser.new_page()
|
||||
@ -1877,9 +1877,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = webkit.launch()
|
||||
page = browser.new_page()
|
||||
@ -2146,9 +2146,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = await chromium.launch()
|
||||
page = await browser.new_page()
|
||||
@ -2165,9 +2165,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = chromium.launch()
|
||||
page = browser.new_page()
|
||||
|
@ -41,9 +41,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = await webkit.launch()
|
||||
context = await browser.new_context()
|
||||
@ -59,9 +59,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = webkit.launch()
|
||||
context = browser.new_context()
|
||||
@ -1726,9 +1726,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = await webkit.launch(headless=false)
|
||||
context = await browser.new_context()
|
||||
@ -1752,9 +1752,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = webkit.launch(headless=false)
|
||||
context = browser.new_context()
|
||||
@ -1979,7 +1979,7 @@ public class Example {
|
||||
```python async
|
||||
import asyncio
|
||||
import hashlib
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
def sha256(text):
|
||||
m = hashlib.sha256()
|
||||
@ -1987,7 +1987,7 @@ def sha256(text):
|
||||
return m.hexdigest()
|
||||
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = await webkit.launch(headless=False)
|
||||
page = await browser.new_page()
|
||||
@ -2011,7 +2011,7 @@ asyncio.run(main())
|
||||
|
||||
```python sync
|
||||
import hashlib
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def sha256(text):
|
||||
m = hashlib.sha256()
|
||||
@ -2019,7 +2019,7 @@ def sha256(text):
|
||||
return m.hexdigest()
|
||||
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = webkit.launch(headless=False)
|
||||
page = browser.new_page()
|
||||
@ -4094,9 +4094,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = await webkit.launch()
|
||||
page = await browser.new_page()
|
||||
@ -4111,9 +4111,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
browser = webkit.launch()
|
||||
page = browser.new_page()
|
||||
@ -4712,9 +4712,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = await chromium.launch()
|
||||
page = await browser.new_page()
|
||||
@ -4731,9 +4731,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = chromium.launch()
|
||||
page = browser.new_page()
|
||||
|
@ -35,9 +35,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
chromium = playwright.chromium # or "firefox" or "webkit".
|
||||
browser = await chromium.launch()
|
||||
page = await browser.new_page()
|
||||
@ -52,9 +52,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
chromium = playwright.chromium # or "firefox" or "webkit".
|
||||
browser = chromium.launch()
|
||||
page = browser.new_page()
|
||||
@ -115,9 +115,9 @@ const iPhone = devices['iPhone 6'];
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
iphone = playwright.devices["iPhone 6"]
|
||||
browser = await webkit.launch()
|
||||
@ -134,9 +134,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
webkit = playwright.webkit
|
||||
iphone = playwright.devices["iPhone 6"]
|
||||
browser = webkit.launch()
|
||||
|
@ -76,9 +76,9 @@ browser.close();
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
tag_selector = """
|
||||
{
|
||||
// Returns the first element matching given selector in the root's subtree.
|
||||
@ -114,9 +114,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
tag_selector = """
|
||||
{
|
||||
// Returns the first element matching given selector in the root's subtree.
|
||||
|
@ -25,9 +25,9 @@ const playwright = require('playwright');
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError
|
||||
from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
browser = await playwright.chromium.launch()
|
||||
page = await browser.new_page()
|
||||
try:
|
||||
|
@ -122,9 +122,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
# create a chromium browser instance
|
||||
chromium = playwright.chromium
|
||||
browser = await chromium.launch()
|
||||
@ -142,9 +142,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
# create a chromium browser instance
|
||||
chromium = playwright.chromium
|
||||
browser = chromium.launch()
|
||||
|
@ -33,13 +33,13 @@ const { chromium } = require('playwright');
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
path_to_extension = "./my-extension"
|
||||
user_data_dir = "/tmp/test-user-data-dir"
|
||||
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
context = await playwright.chromium.launch_persistent_context(
|
||||
user_data_dir,
|
||||
headless=False,
|
||||
@ -67,13 +67,13 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
path_to_extension = "./my-extension"
|
||||
user_data_dir = "/tmp/test-user-data-dir"
|
||||
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
context = playwright.chromium.launch_persistent_context(
|
||||
user_data_dir,
|
||||
headless=False,
|
||||
|
@ -43,9 +43,9 @@ const context = await browser.newContext({
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
iphone_13 = playwright.devices['iPhone 13']
|
||||
browser = await playwright.webkit.launch(headless=False)
|
||||
context = await browser.new_context(
|
||||
@ -59,9 +59,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
iphone_13 = playwright.devices['iPhone 13']
|
||||
browser = playwright.webkit.launch(headless=False)
|
||||
context = browser.new_context(
|
||||
|
@ -271,9 +271,9 @@ public class Example {
|
||||
|
||||
```python async
|
||||
import asyncio
|
||||
from playwright.async_api import async_playwright
|
||||
from playwright.async_api import async_playwright, Playwright
|
||||
|
||||
async def run(playwright):
|
||||
async def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = await chromium.launch()
|
||||
page = await browser.new_page()
|
||||
@ -290,9 +290,9 @@ asyncio.run(main())
|
||||
```
|
||||
|
||||
```python sync
|
||||
from playwright.sync_api import sync_playwright
|
||||
from playwright.sync_api import sync_playwright, Playwright
|
||||
|
||||
def run(playwright):
|
||||
def run(playwright: Playwright):
|
||||
chromium = playwright.chromium
|
||||
browser = chromium.launch()
|
||||
page = browser.new_page()
|
||||
|
@ -15,18 +15,18 @@ function transformValue(input, isSync) {
|
||||
let match = line.match(/const { (\w+) } = require\('playwright'\);/);
|
||||
if (match) {
|
||||
if (isSync) {
|
||||
out.push('from playwright.sync_api import sync_playwright');
|
||||
out.push('from playwright.sync_api import sync_playwright, Playwright');
|
||||
out.push('');
|
||||
out.push('def run(playwright):');
|
||||
out.push('def run(playwright: Playwright):');
|
||||
out.push(` ${match[1]} = playwright.${match[1]}`);
|
||||
suffix.push(``);
|
||||
suffix.push(`with sync_playwright() as playwright:`);
|
||||
suffix.push(` run(playwright)`);
|
||||
} else {
|
||||
out.push('import asyncio');
|
||||
out.push('from playwright.async_api import async_playwright');
|
||||
out.push('from playwright.async_api import async_playwright, Playwright');
|
||||
out.push('');
|
||||
out.push('async def run(playwright):');
|
||||
out.push('async def run(playwright: Playwright):');
|
||||
out.push(` ${match[1]} = playwright.${match[1]}`);
|
||||
suffix.push(``);
|
||||
suffix.push(`async def main():`);
|
||||
|
Loading…
Reference in New Issue
Block a user