From 5cf130c8f6d665b3d96e6caffd561c78039d1f2d Mon Sep 17 00:00:00 2001 From: Eugenio Lacuesta Date: Wed, 18 Sep 2024 20:38:44 -0300 Subject: [PATCH] Adjust typing for PageMethod --- scrapy_playwright/page.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scrapy_playwright/page.py b/scrapy_playwright/page.py index 8112bf1..b33cefe 100644 --- a/scrapy_playwright/page.py +++ b/scrapy_playwright/page.py @@ -1,4 +1,6 @@ -from typing import Any, Callable +from typing import Any, Callable, Union + +from playwright.async_api import Page __all__ = ["PageMethod"] @@ -8,10 +10,12 @@ class PageMethod: """ Represents a method to be called (and awaited if necessary) on a Playwright page, such as "click", "screenshot", "evaluate", etc. + + If a callable is received, it will be called with the page as its only argument. """ - def __init__(self, method: str | Callable, *args, **kwargs) -> None: - self.method: str | Callable = method + def __init__(self, method: Union[str, Callable[[Page], Any]], *args, **kwargs) -> None: + self.method: Union[str, Callable[[Page], Any]] = method self.args: tuple = args self.kwargs: dict = kwargs self.result: Any = None