From c7802a8e1b0f6a5710b4ae9499ee536a650433a0 Mon Sep 17 00:00:00 2001 From: Muhamed Fazal PS Date: Wed, 15 Jul 2026 18:02:15 +0530 Subject: [PATCH] fix: LazyChoices compatibility with Python 3.14+ (#1641) Python 3.14+ argparse validates default against choices at registration time. LazyChoices set self.choices = self, which triggered eager getter calls during parser construction, causing test_lazy_choices_help to fail. Fix: removed self.choices = self from __init__, added manual choice validation in __call__ raising ArgumentError when value isn't in loaded choices. Fixes #1641 --- httpie/cli/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/httpie/cli/utils.py b/httpie/cli/utils.py index ad27da37f7..957baab5a0 100644 --- a/httpie/cli/utils.py +++ b/httpie/cli/utils.py @@ -44,7 +44,6 @@ def __init__( self._help: Optional[str] = None self._obj: Optional[Iterable[T]] = None super().__init__(*args, **kwargs) - self.choices = self def load(self) -> T: if self._obj is None or not self.cache: @@ -76,4 +75,10 @@ def __iter__(self) -> Iterator[T]: return iter(self.load()) def __call__(self, parser, namespace, values, option_string=None): + if self.load() is not None and values not in self.load(): + raise argparse.ArgumentError( + self, + f"invalid choice: {values!r} " + f"(choose from {{{', '.join(str(c) for c in self.load())}}})", + ) setattr(namespace, self.dest, values)