Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
"sphinx.ext.viewcode",
]

autodoc_default_options = {
"exclude-members": "type",
}

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ async = ["httpx>=0.24"]
tests = ["pytest", "retry", "selenium"]
docs = ["sphinx"]

[tool.setuptools.package-data]
python_anticaptcha = ["py.typed"]

[tool.setuptools-scm]
fallback_version = "0.0.0"

Expand Down
17 changes: 12 additions & 5 deletions python_anticaptcha/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import time
import json
import warnings
from types import TracebackType
from typing import Any

from urllib.parse import urljoin
from .exceptions import AnticaptchaException
from .tasks import BaseTask

SLEEP_EVERY_CHECK_FINISHED = 3
MAXIMUM_JOIN_TIME = 60 * 5
Expand Down Expand Up @@ -111,14 +113,19 @@ def __init__(
)
self.session = requests.Session()

def __enter__(self):
def __enter__(self) -> AnticaptchaClient:
return self

def __exit__(self, exc_type, exc_val, exc_tb):
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> bool:
self.session.close()
return False

def close(self):
def close(self) -> None:
self.session.close()

def __repr__(self) -> str:
Expand Down Expand Up @@ -146,7 +153,7 @@ def _check_response(self, response: dict[str, Any]) -> None:
response["errorId"], response["errorCode"], response["errorDescription"]
)

def createTask(self, task: Any) -> Job:
def createTask(self, task: BaseTask) -> Job:
request = {
"clientKey": self.client_key,
"task": task.serialize(),
Expand All @@ -161,7 +168,7 @@ def createTask(self, task: Any) -> Job:
self._check_response(response)
return Job(self, response["taskId"])

def createTaskSmee(self, task: Any, timeout: int = MAXIMUM_JOIN_TIME) -> Job:
def createTaskSmee(self, task: BaseTask, timeout: int = MAXIMUM_JOIN_TIME) -> Job:
"""
Beta method to stream response from smee.io
"""
Expand Down
4 changes: 2 additions & 2 deletions python_anticaptcha/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, error_id: int | str | None, error_code: int | str, error_desc


class InvalidWidthException(AnticaptchaException):
def __init__(self, width):
def __init__(self, width: int) -> None:
self.width = width
msg = "Invalid width (%s). Can be one of these: 100, 50, 33, 25." % (
self.width,
Expand All @@ -24,7 +24,7 @@ def __init__(self, width):


class MissingNameException(AnticaptchaException):
def __init__(self, cls):
def __init__(self, cls: type) -> None:
self.cls = cls
msg = 'Missing name data in {0}. Provide {0}.__init__(name="X") or {0}.serialize(name="X")'.format(
str(self.cls)
Expand Down
Loading