Add type hints and modernize code style with ruff/mypy#130
Merged
Conversation
- Add .pre-commit-config.yaml with ruff (lint + format) and mypy hooks - Add ruff and mypy tool configuration to pyproject.toml - Add prek-action lint job to GitHub Actions workflow - Replace Docker-based flake8/black lint targets with ruff in Makefile - Add lint/typecheck environments to tox.ini - Fix type annotations: properly type Job class attributes, BaseTask.type, on_check callback parameter, and __exit__ return type - Fix ruff issues: remove unused Union import, sort imports, remove unicode literals, use f-strings, add stacklevel to warnings.warn - Exclude examples/ from ruff (documentation scripts with intentional patterns) https://claude.ai/code/session_01NzfYD4hhH5nqhu8mgnMXPt
…ctions-ci-75v3Y # Conflicts: # python_anticaptcha/base.py
The hook was checking all files (tests, examples, docs) which have untyped functions. Restrict to the package directory only. https://claude.ai/code/session_01NzfYD4hhH5nqhu8mgnMXPt
Rename second assignment to create_response to avoid type conflict with the Response object from the initial HEAD request. https://claude.ai/code/session_01NzfYD4hhH5nqhu8mgnMXPt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR modernizes the codebase by adding comprehensive type hints throughout the project and applying consistent code formatting using ruff and mypy. The changes improve code quality, maintainability, and IDE support while maintaining full backward compatibility.
Key Changes
Type Hints & Type Safety
base.py,tasks.py, andexceptions.pyclient: AnticaptchaClient,task_id: int)Jobmethods to help type checkers understand_last_resultis not NoneAnticaptchaClient.__exit__()toLiteral[False]for accuracyUniontypes with modern|syntax (e.g.,str | Path | bytes | BinaryIO)Code Formatting & Style
.format()calls to f-strings throughout the codebaseUnionimports in favor of|operatorBug Fixes & Improvements
report_incorrect()to passtask_idparameter toreportIncorrectImage()stacklevel=2to deprecation warningcreateTaskSmee()when no matching response receivedreportIncorrectImage()usingbool()conversioncreateTaskSmee()(task→task_datato avoid shadowing)Tooling & Configuration
.pre-commit-config.yamlwith ruff and mypy hookspyproject.tomllintandtypechecktargets to Makefiletoxenvironment for lint testingDocumentation
# -*- coding: utf-8 -*-headersu""string prefixes indocs/conf.pyNotable Implementation Details
Jobmethods are strategically placed after_update()calls to ensure_last_resultis populatedon_checkcallback parameter now has explicit type signature:Callable[[int, str | None], None] | Nonerequestslibraryhttps://claude.ai/code/session_01NzfYD4hhH5nqhu8mgnMXPt