argparser.py: HTTPieArgumentParser has high cyclomatic complexity and mixed responsibilities

Open
#1,828 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Refactor
Clarity
Mostly clear
Activity status
Stale
Tech stack
python

Research direction

Start with httpie/cli/argparser.py, especially _process_auth, _process_output_options, and the existing TODOs. Review pull request #1827 to understand the work already underway and confirm the intended scope with maintainers. Done means the agreed refactoring is complete and its affected tests pass.

Written by the indexing model from the issue text.

Description

Overview

Automated complexity analysis of the httpie/ package ranked httpie/cli/argparser.py as the highest-complexity module. The findings below expand on what the existing developer TODO comments already acknowledge.

Findings

_process_auth — cyclomatic complexity ~20, max nesting 5 levels
# TODO: refactor & simplify this method.   (line 283)

The method (74 lines) handles six distinct concerns in sequence:

  1. Extracting embedded URL credentials (user:pass@host)
  2. Looking up .netrc credentials
  3. Resolving the auth plugin
  4. Validating --auth required
  5. Parsing / prompting for credentials
  6. Calling plugin.get_auth()

Three nearly-identical AuthCredentials(key=…, value=…, sep=…, orig=…) blocks are copy-pasted rather than shared.

_process_output_options — nested closure

A check_options function is defined inside the method body and called twice immediately after — a straightforward candidate for extraction to class level.

Class-level TODO (line 79)
# TODO: refactor and design type-annotated data structures
#       for raw args + parsed args and keep things immutable.

HTTPieArgumentParser has no return type annotations on its 14 methods.

Metrics (automated scan)

Metric Value
Module cyclomatic complexity ~104
if/elif count 75
Max nesting depth 9 levels
Longest single method 75 lines (_process_auth)
Methods with type annotations 0 / 14

Suggestion

A PR (#1827) is open that addresses _process_auth specifically — decomposing it into four focused helpers and adding return-type annotations. Happy to discuss scope or approach if this direction is welcome.


Found via automated codebase complexity scan.

Dominant language
Python
Stars
38.6k
Forks
4k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from httpie/cli

All issues in httpie/cli

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.