Add YAPF style + ignore, and format tracked Python files

This commit is contained in:
2025-12-29 18:42:02 -08:00
parent c019c00aed
commit 507946a3e4
108 changed files with 11664 additions and 6494 deletions

View File

@@ -18,9 +18,13 @@ except Exception as exc: # pragma: no cover
PlaywrightTimeoutError = TimeoutError # type: ignore
sync_playwright = None # type: ignore
# Re-export for consumers (e.g. cmdlets catching navigation timeouts)
__all__ = ["HAS_PLAYWRIGHT", "PlaywrightTimeoutError", "PlaywrightTool", "PlaywrightDefaults"]
__all__ = [
"HAS_PLAYWRIGHT",
"PlaywrightTimeoutError",
"PlaywrightTool",
"PlaywrightDefaults"
]
def _get_nested(config: Dict[str, Any], *path: str) -> Any:
@@ -66,7 +70,8 @@ class PlaywrightTool:
"""
def __init__(self, config: Optional[Dict[str, Any]] = None) -> None:
self._config: Dict[str, Any] = dict(config or {})
self._config: Dict[str,
Any] = dict(config or {})
self.defaults = self._load_defaults()
def _load_defaults(self) -> PlaywrightDefaults:
@@ -75,7 +80,8 @@ class PlaywrightTool:
tool_block = _get_nested(cfg, "tool", "playwright")
if not isinstance(tool_block, dict):
tool_block = {}
pw_block = cfg.get("playwright") if isinstance(cfg.get("playwright"), dict) else {}
pw_block = cfg.get("playwright") if isinstance(cfg.get("playwright"),
dict) else {}
if not isinstance(pw_block, dict):
pw_block = {}
@@ -90,7 +96,9 @@ class PlaywrightTool:
return fallback if val is None else val
browser = str(_get("browser", defaults.browser)).strip().lower() or "chromium"
if browser not in {"chromium", "firefox", "webkit"}:
if browser not in {"chromium",
"firefox",
"webkit"}:
browser = "chromium"
headless_raw = _get("headless", defaults.headless)
@@ -145,12 +153,15 @@ class PlaywrightTool:
h = self.defaults.headless if headless is None else bool(headless)
ua = self.defaults.user_agent if user_agent is None else str(user_agent)
vw = self.defaults.viewport_width if viewport_width is None else int(viewport_width)
vh = self.defaults.viewport_height if viewport_height is None else int(viewport_height)
vw = self.defaults.viewport_width if viewport_width is None else int(
viewport_width
)
vh = self.defaults.viewport_height if viewport_height is None else int(
viewport_height
)
ihe = (
self.defaults.ignore_https_errors
if ignore_https_errors is None
else bool(ignore_https_errors)
if ignore_https_errors is None else bool(ignore_https_errors)
)
# Support Playwright-native headers/user-agent.
@@ -158,7 +169,9 @@ class PlaywrightTool:
# we omit the user_agent override so Playwright uses its bundled Chromium UA.
ua_value: Optional[str]
ua_text = str(ua or "").strip()
if not ua_text or ua_text.lower() in {"native", "playwright", "default"}:
if not ua_text or ua_text.lower() in {"native",
"playwright",
"default"}:
ua_value = None
else:
ua_value = ua_text
@@ -178,10 +191,14 @@ class PlaywrightTool:
headless=h,
args=["--disable-blink-features=AutomationControlled"],
)
context_kwargs: Dict[str, Any] = {
"viewport": {"width": vw, "height": vh},
"ignore_https_errors": ihe,
}
context_kwargs: Dict[str,
Any] = {
"viewport": {
"width": vw,
"height": vh
},
"ignore_https_errors": ihe,
}
if ua_value is not None:
context_kwargs["user_agent"] = ua_value
@@ -209,7 +226,9 @@ class PlaywrightTool:
"""Navigate with configured timeout."""
try:
page.goto(
url, timeout=int(self.defaults.navigation_timeout_ms), wait_until="domcontentloaded"
url,
timeout=int(self.defaults.navigation_timeout_ms),
wait_until="domcontentloaded"
)
except Exception:
raise