Skip to content

Fix inconsistent argument parsing behavior across Python versions - #1918

Draft
vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/argparse-consistency
Draft

Fix inconsistent argument parsing behavior across Python versions#1918
vinayK34 wants to merge 1 commit into
httpie:masterfrom
vinayK34:fix/argparse-consistency

Conversation

@vinayK34

@vinayK34 vinayK34 commented Aug 6, 2026

Copy link
Copy Markdown

This PR fixes issue #1838 where the position of optional flags like -v affects argument parsing differently depending on the Python version.

The problem was caused by using parse_known_args() in the argument parsers, which behaves inconsistently between Python 3.12 and 3.13+. Python 3.13 introduced improvements to argparse that better handle intermixed optional and positional arguments.

By switching to parse_intermixed_args(), which is available since Python 3.7, we ensure consistent behavior across all supported Python versions (3.11, 3.12, and 3.13+).

This change modifies:

  • httpie/cli/argparser.py: Updated BaseHTTPieArgumentParser.parse_args() and HTTPieArgumentParser.parse_args() to use parse_intermixed_args() instead of parse_known_args()
  • Added parse_intermixed_args() method to HTTPieManagerArgumentParser for consistency

Fixes #1838

This change modifies the argument parser to use `parse_intermixed_args()` instead of `parse_known_args()` to ensure consistent behavior across Python versions. This addresses issue httpie#1838 where the position of optional flags like `-v` affects argument parsing differently depending on the Python version.

The fix ensures that optional arguments can be placed before or after positional arguments consistently across all supported Python versions (3.11, 3.12, and 3.13+).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent argument parsing behavior across Python versions (< 3.13 vs 3.13+)

1 participant