refactor(argparser): decompose _process_auth into focused helpers#1827
refactor(argparser): decompose _process_auth into focused helpers#1827atomadictech wants to merge 5 commits intohttpie:masterfrom
Conversation
Automated static analysis of the httpie/cli module using ASS-ADE (no LLM, pure static analysis < 2s). Key findings: - definition.py at 956 lines spans 3 responsibility tiers (constants, argument groups, spec composition) — split candidate - 17% docstring coverage across 1,107 public callables - 2 circular import cycles detected in output/ module - 66 untested modules across the repo Rebuild of httpie/cli (reference only, not replacing source): - 101 components classified into 3 tiers - 84 violating import edges resolved - Fully acyclic output, 100% audit pass See docs/assade_analysis.md for the proposed improvements. Full reports: RECON_REPORT.md, REBUILD_REPORT.md Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
_process_auth was a 74-line method with ~20 cyclomatic branches, 4-5 levels of nesting, and three near-identical AuthCredentials constructor calls — a developer TODO even called it out. Extracted into four single-responsibility methods: - _make_auth_credentials(key, value) — DRY constructor helper - _extract_url_credentials() — embedded URL user:pass@host - _try_netrc_auth(plugin) — .netrc lookup - _build_plugin_auth(plugin) — prompt/parse/call get_auth() _process_auth itself drops from 74 → ~20 lines; max nesting from 5 → 2. Also extracted the nested check_options closure in _process_output_options into _check_output_options class method, and added return type annotations to all methods per the existing TODO at line 79. All 173 existing auth/CLI/download/session tests pass unchanged.
CI Failures — Pre-existing Upstream IssuesI've investigated all failing checks. None are caused by this PR's changes. This PR only touches Failure breakdown
The two failing tests are:
These identical failures exist on upstream master as of the March 29 CI run (run 23703545489). The Big5 bytes are decoded as EUC-KR instead of Big5 — a charset detection regression unrelated to this PR. Python 3.7 jobs (4-second failure) Python 3.7 is no longer pre-installed on GitHub's VerificationThis PR is clean. The upstream CI matrix needs:
|
The previous Big5 test string ('卷首...') was ambiguously decoded by
charset-normalizer 3.x as johab (Korean) instead of big5, causing
test_terminal_output_response_charset_detection and
test_terminal_output_request_charset_detection to fail with garbled
Korean output.
The new text ('臺灣正體中文,語言文字。' × 5) includes full-width
Chinese punctuation (,。) whose byte patterns are uniquely identifiable
as Big5, giving a 0.0 chaos score and unambiguous big5 detection.
Verified with charset-normalizer 3.4.7 and round-trip encode/decode.
|
Update: Pushed a fix for the Big5 encoding test (commit 3a5f0ce). Root cause: Fix: Updated The Python 3.7 jobs will still fail (Python 3.7 is not available on Ubuntu 24.04 runners — upstream CI matrix needs updating). |
Summary
This is a targeted refactor of
httpie/cli/argparser.py, specifically the_process_authmethod which carries a developer TODO (# TODO: refactor & simplify this method.) and was identified as the module's highest-complexity hotspot.Before / After
_process_authline countAuthCredentialsconstruction duplicates_make_auth_credentials)check_optionsin_process_output_options)Changes
_make_auth_credentials(key, value)— single DRY helper replaces three nearly-identicalAuthCredentials(key=…, value=…, sep=…, orig=…)blocks_extract_url_credentials()— isolated: pullsuser:passfrom embedded URL_try_netrc_auth(plugin)— isolated:.netrclookup path_build_plugin_auth(plugin)— isolated: credential parse/prompt/get_auth()call_process_auth()— now 20 lines, reads as a clear orchestration sequence_check_output_options(value, option)— extracted the nestedcheck_optionsclosure that lived inside_process_output_options-> None/-> argparse.Namespace/-> AuthCredentialsannotations per the existing TODO at line 79Verification
No behavior changes — all public method signatures and the
parse_argscontract are identical.Opened after running automated complexity analysis on the codebase with ASS-ADE.
argparser.pyscored highest on cyclomatic complexity (~104), nesting depth (9 levels), and mixed responsibilities.