Skip to content

Commit ca02a00

Browse files
ad-mAdam Dobrawyclaude
authored
Add __repr__ to Job, AnticaptchaClient, and BaseTask (#123)
Improves debugging and REPL experience by showing useful info instead of unhelpful <object at 0x...> output. Co-authored-by: Adam Dobrawy <naczelnik@jawne.info.pl> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f806813 commit ca02a00

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

python_anticaptcha/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ def report_incorrect_image(self) -> bool:
6161
def report_incorrect_recaptcha(self) -> bool:
6262
return self.client.reportIncorrectRecaptcha(self.task_id)
6363

64+
def __repr__(self) -> str:
65+
status = self._last_result.get("status") if self._last_result else None
66+
if status:
67+
return f"<Job task_id={self.task_id} status={status!r}>"
68+
return f"<Job task_id={self.task_id}>"
69+
6470
def join(self, maximum_time: int | None = None) -> None:
6571
elapsed_time = 0
6672
maximum_time = maximum_time or MAXIMUM_JOIN_TIME
@@ -115,6 +121,11 @@ def __exit__(self, exc_type, exc_val, exc_tb):
115121
def close(self):
116122
self.session.close()
117123

124+
def __repr__(self) -> str:
125+
from urllib.parse import urlparse
126+
host = urlparse(self.base_url).hostname or self.base_url
127+
return f"<AnticaptchaClient host={host!r}>"
128+
118129
@property
119130
def client_ip(self) -> str:
120131
if not hasattr(self, "_client_ip"):

python_anticaptcha/tasks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def serialize(self, **result: Any) -> dict[str, Any]:
1212
result["type"] = self.type
1313
return result
1414

15+
def __repr__(self) -> str:
16+
attrs = {k: v for k, v in self.__dict__.items()
17+
if not k.startswith("_") and v is not None}
18+
fields = " ".join(f"{k}={v!r}" for k, v in attrs.items())
19+
return f"<{self.__class__.__name__} {fields}>"
20+
1521

1622
class UserAgentMixin(BaseTask):
1723
def __init__(self, *args: Any, **kwargs: Any) -> None:

0 commit comments

Comments
 (0)