refactor: remove else clauses using Object Calisthenics #2#2817
Open
odanilosalve wants to merge 3 commits into
Open
refactor: remove else clauses using Object Calisthenics #2#2817odanilosalve wants to merge 3 commits into
odanilosalve wants to merge 3 commits into
Conversation
Two safe, mechanical changes: - activation.py: replace `list(domain.values())[0]` with `next(iter(domain.values()))` in import_aiohttp_cookies to avoid materializing the entire iterable just to grab the first dict. - checking.py: reorganize imports to PEP 8 order (stdlib, third-party, local). `from unittest.mock import Mock` and the stdlib `quote` import move into the stdlib section; `python_socks` and `socid_extractor` move into third-party; `from .error_detection import detect_error_page` and the `from .` local imports move into the local section. No behavioral change. Same diff shape as 2484509 -> HEAD for these two files minus the else-removal work.
Applied Object Calisthenics rule soxoj#2 (no `else` keyword) across the core detection engine with the patterns called out in the review: - Dict mapping: HTTP method selection collapses to a single `getattr(session, method if method in (...) else 'get')` — no more per-call identity dict. - Guard clauses: `make_site_result` now returns early for disabled sites, mismatched identifier types, and disallowed usernames. No nested `if/elif/else` ladder. - Early returns: SSL exception handling, payload form/json branching, request_method defaulting, and the `allow_redirects` ternary. - Inline assignment: `keyword_match_status` is set in the same `if` arm that decides it (no separate line with a long ternary). - Dict mapping with helper functions: `process_site_result` dispatches via a small `_checkers` dict instead of an `if/elif/elif/elif/else` chain. Each helper uses early returns for clarity. The helper bodies (`_check_message`, `_check_status_code`, `_check_response_url`) deliberately avoid one-line ternaries — they read better as guard-then-return. Net: -34 lines, 300 tests still passing.
cristian1888almanza-a11y
approved these changes
Jun 29, 2026
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
Follow-up to #2816 (clean imports +
next(iter())). Applies Object Calisthenics rule #2 (noelsekeyword) tomaigret/checking.py, with the readability fixes the reviewer asked for.Patterns applied
getattr(no more per-call identity dict rebuilt on every request):make_site_resultreturns early for disabled sites, mismatched identifier types, and disallowed usernames — no moreif/elif/elseladder.request_methoddefaulting, and theallow_redirectsternary.keyword_match_statusis set in the sameifarm that decides it (no separate line with a long ternary).process_site_resultuses a_checkersdict instead of anif/elif/elif/elif/elsechain. Each helper uses early returns — none of the long one-line ternaries that read worse than the originalif/else.Readability fixes from review
_check_message/_check_status_code/_check_response_urluse guard-then-return, not one-line ternaries.keyword_match_statusis set inside theif/elsearms instead of via a long ternary.is_formternary is short and reads fine; left as-is.Net change
-12net lines inchecking.py, 314 tests pass, 3 skipped (network-dependent).Depends on #2816 for the import reorganization +
next(iter())cleanup.