fix: replace bare assert with user-friendly error in _guess_method#1805
Closed
funsaized wants to merge 2 commits intohttpie:masterfrom
Closed
fix: replace bare assert with user-friendly error in _guess_method#1805funsaized wants to merge 2 commits intohttpie:masterfrom
funsaized wants to merge 2 commits intohttpie:masterfrom
Conversation
- test_cli_ui: argparse in Python 3.12.4+ no longer quotes choices in error messages. Detect quoting behavior at runtime so the test passes on both old and new Python versions. - test_encoding: replace repetitive big5 text with varied Traditional Chinese text so charset_normalizer can reliably distinguish big5 from other CJK encodings (johab/euc-kr).
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.
Summary
Fixes #1614
When
_guess_method()encounters a state whereargs.methodisNonebutargs.request_itemsis non-empty, it crashes with a bareAssertionError. This can happen when users place optional flags between METHOD and URL (e.g.http POST --auth-type bearer --auth token URL), causing Python'sargparseto misassign positional arguments — particularly on Python 3.13+.Changes
httpie/cli/argparser.py: Replaceassert not self.args.request_itemswith aself.error()call that prints the correct usage syntax and a link to the docs.tests/test_cli.py: Addtest_guess_when_method_not_set_but_request_items_presentcovering the previously-crashing code path.Before
After