Skip to content

Commit 2f14b38

Browse files
AndreiDrangclaude
andcommitted
refactor(core): fix forward refs and modernize instrument annotations
Why: * the quoted "CaptchaParams" forward references in both instruments resolved to no import, so static analysis flagged them as undefined * Optional[...] and quoted annotations predate lazy annotation support What: * add a TYPE_CHECKING-guarded CaptchaParams import to break the annotation-only import cycle with base.py * add from __future__ import annotations and switch the single Optional[dict] parameter to dict | None (lazy, so python 3.8+ stays supported) * unquote the CaptchaParams parameter annotation no runtime behavior change: the guard never executes and annotations are never evaluated; the full mocked suite passes identically Changes: * src/python3_capsolver/core/sio_captcha_instrument.py: typing hygiene * src/python3_capsolver/core/aio_captcha_instrument.py: typing hygiene Stats: * 2 files changed * +10/-4 lines Co-authored-by: Claude <noreply@anthropic.com>
1 parent bb594d9 commit 2f14b38

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

‎src/python3_capsolver/core/aio_captcha_instrument.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import logging
3-
from typing import Optional
5+
from typing import TYPE_CHECKING
46
from urllib import parse
57

68
import aiohttp
@@ -11,6 +13,9 @@
1113
from .serializer import CaptchaResponseSer
1214
from .captcha_instrument import CaptchaInstrumentBase
1315

16+
if TYPE_CHECKING:
17+
from .base import CaptchaParams
18+
1419
__all__ = ("AIOCaptchaInstrument",)
1520

1621

@@ -19,7 +24,7 @@ class AIOCaptchaInstrument(CaptchaInstrumentBase):
1924
Instrument for working with async captcha
2025
"""
2126

22-
def __init__(self, captcha_params: "CaptchaParams"):
27+
def __init__(self, captcha_params: CaptchaParams):
2328
super().__init__()
2429
self.captcha_params = captcha_params
2530
self.created_task_data = CaptchaResponseSer
@@ -99,7 +104,7 @@ async def __get_result(self, url_postfix: str = EndpointPostfixEnm.GET_TASK_RESU
99104

100105
@staticmethod
101106
async def send_post_request(
102-
payload: Optional[dict] = None,
107+
payload: dict | None = None,
103108
url_postfix: EndpointPostfixEnm = EndpointPostfixEnm.GET_BALANCE,
104109
) -> dict:
105110
"""

‎src/python3_capsolver/core/sio_captcha_instrument.py‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import annotations
2+
13
import time
24
import logging
3-
from typing import Optional
5+
from typing import TYPE_CHECKING
46
from urllib import parse
57

68
import requests
@@ -12,6 +14,9 @@
1214
from .serializer import CaptchaResponseSer
1315
from .captcha_instrument import CaptchaInstrumentBase
1416

17+
if TYPE_CHECKING:
18+
from .base import CaptchaParams
19+
1520
__all__ = ("SIOCaptchaInstrument",)
1621

1722

@@ -20,7 +25,7 @@ class SIOCaptchaInstrument(CaptchaInstrumentBase):
2025
Instrument for working with sync captcha
2126
"""
2227

23-
def __init__(self, captcha_params: "CaptchaParams"):
28+
def __init__(self, captcha_params: CaptchaParams):
2429
super().__init__()
2530
self.captcha_params = captcha_params
2631
self.created_task_data = CaptchaResponseSer
@@ -106,7 +111,7 @@ def __get_result(self, url_postfix: str = EndpointPostfixEnm.GET_TASK_RESULT.val
106111

107112
@staticmethod
108113
def send_post_request(
109-
payload: Optional[dict] = None,
114+
payload: dict | None = None,
110115
session: requests.Session = requests.Session(),
111116
url_postfix: EndpointPostfixEnm = EndpointPostfixEnm.GET_BALANCE,
112117
) -> dict:

0 commit comments

Comments
 (0)