refactor(argparser): decompose _process_auth into focused helpers#1827
Open
atomadictech wants to merge 2 commits intohttpie:masterfrom
Open
refactor(argparser): decompose _process_auth into focused helpers#1827atomadictech wants to merge 2 commits intohttpie:masterfrom
atomadictech wants to merge 2 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.
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 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.