fix: defer LazyChoices getter call until --help is used (Python 3.14 compat)#1720
Open
juliosuas wants to merge 1 commit intohttpie:masterfrom
Open
fix: defer LazyChoices getter call until --help is used (Python 3.14 compat)#1720juliosuas wants to merge 1 commit intohttpie:masterfrom
juliosuas wants to merge 1 commit intohttpie:masterfrom
Conversation
…compat) Python 3.14 added a _check_help() call inside ArgumentParser.add_argument() that reads action.help during parser construction. Previously, only parse_args(['--help']) triggered help formatting. LazyChoices was designed to call getter() lazily (only when --help is passed), but with Python 3.14 the help property was accessed and triggered getter() eagerly during add_argument(), breaking test_lazy_choices_help. Fix: 1. In LazyChoices: separate _resolve_help() from the help property. The property now returns self._help as-is (None until resolved), without calling load() / getter(). A _help_resolved flag tracks whether resolution has happened. 2. In BaseHTTPieArgumentParser: override format_help() to call action._resolve_help() on all LazyChoices actions just before rendering the help text. This ensures getter() is called exactly once and only when --help is actually used. Fixes test_lazy_choices_help on Python 3.14. Closes httpie#1641
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
Closes #1641.
Python 3.14 added a
_check_help()call insideArgumentParser.add_argument()that readsaction.helpduring parser construction. Previously, onlyparse_args(['--help'])triggered help formatting.LazyChoiceswas designed to callgetter()lazily — only when--helpis passed — but Python 3.14 causedgetter()to be invoked eagerly duringadd_argument(), breakingtest_lazy_choices_help.Root Cause
LazyChoices.helpwas a property that calledself.load()(which callsgetter()) whenever the help string was requested. In Python 3.14, argparse accessesaction.helpinsideadd_argument()via_check_help() → _expand_help() → _get_help_string() → action.help.Fix
Two small changes:
1.
httpie/cli/utils.py— Separate resolution from the property:_resolve_help()method that callsgetter()and formats the help (deferred)helpproperty returnself._helpas-is without triggering loading_help_resolvedflag to track state2.
httpie/cli/argparser.py— Overrideformat_help()inBaseHTTPieArgumentParser:action._resolve_help()on allLazyChoicesactionsgetter()is called exactly once and only when--helpis actually usedVerification
All
test_lazy_choices_helpassertions pass on Python 3.14:getternot called duringadd_argument()getter/help_formatternot called afterparse_args([])help_formatternot called when passing a value without--help