argparser.py: HTTPieArgumentParser has high cyclomatic complexity and mixed responsibilities
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
- Domain
- cli, developer-experience
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:
- Extracting embedded URL credentials (
user:pass@host) - Looking up
.netrccredentials - Resolving the auth plugin
- Validating
--auth required - Parsing / prompting for credentials
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from httpie/cli
-
new
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug new
Difficulty 4/5 3-5 days Newbie friendliness 48/100
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
bug ci good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
documentation
Difficulty 2/5 Half a day Newbie friendliness 62/100
inmanta/inmanta-core#10835 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
sponsored
Difficulty 2/5 1-3 hours Newbie friendliness 65/100