Skip to content

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

@atomadictech

Description

@atomadictech

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions