From d6c8b8180fb5498e8514b7979841d3f10baa2b8b Mon Sep 17 00:00:00 2001 From: AI Builder Date: Thu, 9 Jul 2026 14:28:38 -0700 Subject: [PATCH] Fix LazyChoices for Python 3.14+ compatibility Remove self.choices = self to prevent argparse from eagerly validating default values at registration time (Python 3.14 behavior change). Move choice validation into __call__ instead. Fixes httpie/cli#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..dda2b875ac 100644 --- a/httpie/cli/utils.py +++ b/httpie/cli/utils.py @@ -1,4 +1,5 @@ import argparse +from argparse import ArgumentError from typing import Any, Callable, Generic, Iterator, Iterable, Optional, TypeVar T = TypeVar('T') @@ -44,7 +45,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 +76,9 @@ def __iter__(self) -> Iterator[T]: return iter(self.load()) def __call__(self, parser, namespace, values, option_string=None): + if values not in self.load(): + raise ArgumentError( + self, + f"invalid choice: {values!r} (choose from {self.load()!r})" + ) setattr(namespace, self.dest, values)