fix: replace assertion error with proper method guessing when optional args precede URL#1879
Open
wahajahmed010 wants to merge 1 commit into
Open
Conversation
…l args precede URL When running httpie with optional arguments (e.g. --auth-type, --auth) between the HTTP method and URL, argparse can misparse the positional arguments, assigning the method to the URL slot and the URL to a request item. This previously caused an AssertionError in _guess_method(). The fix merges the two branches of _guess_method() so that when the method is None and request_items is non-empty, the same URL-as-method recovery logic is applied. This replaces the bare assert with graceful handling. Closes httpie#1614
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.
Description
When running httpie with optional arguments (e.g.
--auth-type,--auth) between the HTTP method and URL, argparse can misparse the positional arguments, assigning the method to the URL slot and the URL to a request item. This previously caused anAssertionErrorin_guess_method().Root Cause
argparse with
nargs="?"for the optional method argument gets confused when optional arguments appear between positional arguments. The method ends up asNoneand the URL is parsed as a request item, triggering the bareassert not self.args.request_items.Fix
Merged the two branches of
_guess_method()so that when the method isNoneandrequest_itemsis non-empty, the same URL-as-method recovery logic is applied. This replaces the bare assert with graceful handling that correctly recovers the method and URL.Testing
https POST --auth-type bearer --auth token123 https://example.orgCloses #1614
This PR was created with AI assistance (OpenClaw OSS Contributor pipeline).