Skip to content

Commit

Permalink
Removed type hinting for decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
Xewdy444 committed Oct 27, 2023
1 parent c414c1d commit ea530a4
Showing 1 changed file with 10 additions and 48 deletions.
58 changes: 10 additions & 48 deletions playwright_recaptcha/recaptchav2/recaptcha_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import re
from abc import ABC, abstractmethod
from functools import wraps
from typing import Awaitable, Callable, Iterable, List, Tuple, Union, overload
from typing import Iterable, List, Tuple, Union

from playwright.async_api import Frame as AsyncFrame
from playwright.async_api import Locator as AsyncLocator
Expand Down Expand Up @@ -68,64 +68,26 @@ def _get_recaptcha_frame_pairs(

return frame_pairs

@overload
@staticmethod
def _check_if_attached(
func: Callable[[AsyncRecaptchaBox], Awaitable[bool]]
) -> Callable[[AsyncRecaptchaBox], Awaitable[bool]]:
...

@overload
@staticmethod
def _check_if_attached(
func: Callable[[SyncRecaptchaBox], bool]
) -> Callable[[SyncRecaptchaBox], bool]:
...

@staticmethod
def _check_if_attached(
func: Union[
Callable[[AsyncRecaptchaBox], Awaitable[bool]],
Callable[[SyncRecaptchaBox], bool],
]
) -> Union[
Callable[[AsyncRecaptchaBox], Awaitable[bool]],
Callable[[SyncRecaptchaBox], bool],
]:
def _check_if_attached(func):
"""
Check if the reCAPTCHA frames are attached
before running the decorated function, otherwise return False.
Parameters
----------
func : Union[
Callable[[AsyncRecaptchaBox], Awaitable[bool]],
Callable[[SyncRecaptchaBox], bool],
]
The function to decorate.
Returns
-------
Union[
Callable[[AsyncRecaptchaBox], Awaitable[bool]],
Callable[[SyncRecaptchaBox], bool],
]
The decorated function.
A decorator for checking if the reCAPTCHA frames are attached
before running the decorated function.
"""

@wraps(func)
def sync_wrapper(recaptcha_box: SyncRecaptchaBox) -> bool:
if recaptcha_box.frames_are_detached():
def sync_wrapper(self: SyncRecaptchaBox) -> bool:
if self.frames_are_detached():
return False

return func(recaptcha_box)
return func(self)

@wraps(func)
async def async_wrapper(recaptcha_box: AsyncRecaptchaBox) -> bool:
if recaptcha_box.frames_are_detached():
async def async_wrapper(self: AsyncRecaptchaBox) -> bool:
if self.frames_are_detached():
return False

return await func(recaptcha_box)
return await func(self)

if asyncio.iscoroutinefunction(func):
return async_wrapper
Expand Down

0 comments on commit ea530a4

Please sign in to comment.