bugfix(community): fix Playwright import paths. (#21395)

- **Description:** Fix import class name exporeted from
'playwright.async_api' and 'playwright.sync_api' to match the correct
name in playwright tool. Change import from inline guard_import to
helper function that calls guard_import to make code more readable in
gmail tool. Upgrade playwright version to 1.43.0
- **Issue:** #21354
- **Dependencies:** upgrade playwright version(this is not required for
the bugfix itself, just trying to keep dependencies fresh. I can remove
the playwright version upgrade if you want.)
This commit is contained in:
Mehrdad Shokri
2024-05-08 23:20:25 +02:00
committed by GitHub
parent aa966b6161
commit f103927b88
2 changed files with 7 additions and 22 deletions

View File

@@ -27,8 +27,8 @@ def lazy_import_playwright_browsers() -> Tuple[Type[AsyncBrowser], Type[SyncBrow
AsyncBrowser and SyncBrowser classes.
"""
return (
guard_import(module_name="playwright.async_api").AsyncBrowser,
guard_import(module_name="playwright.sync_api").SyncBrowser,
guard_import(module_name="playwright.async_api").Browser,
guard_import(module_name="playwright.sync_api").Browser,
)
@@ -41,8 +41,7 @@ class BaseBrowserTool(BaseTool):
@root_validator
def validate_browser_provided(cls, values: dict) -> dict:
"""Check that the arguments are valid."""
guard_import(module_name="playwright.async_api").AsyncBrowser
guard_import(module_name="playwright.sync_api").SyncBrowser
lazy_import_playwright_browsers()
if values.get("async_browser") is None and values.get("sync_browser") is None:
raise ValueError("Either async_browser or sync_browser must be specified.")
return values
@@ -54,6 +53,5 @@ class BaseBrowserTool(BaseTool):
async_browser: Optional[AsyncBrowser] = None,
) -> BaseBrowserTool:
"""Instantiate the tool."""
guard_import(module_name="playwright.async_api").AsyncBrowser
guard_import(module_name="playwright.sync_api").SyncBrowser
lazy_import_playwright_browsers()
return cls(sync_browser=sync_browser, async_browser=async_browser)