Skip to content

fix: LazyChoices compatibility with Python 3.14+ (#1641)#1901

Open
fazalpsinfo-cmyk wants to merge 1 commit into
httpie:masterfrom
fazalpsinfo-cmyk:fix/lazy-choices-python-3.14
Open

fix: LazyChoices compatibility with Python 3.14+ (#1641)#1901
fazalpsinfo-cmyk wants to merge 1 commit into
httpie:masterfrom
fazalpsinfo-cmyk:fix/lazy-choices-python-3.14

Conversation

@fazalpsinfo-cmyk

Copy link
Copy Markdown

Fix: LazyChoices fails on Python 3.14

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__ — raises ArgumentError if the
    value isn't in the loaded choices at parse time

The getter remains fully lazy: it is only called when --help or when a value
is actually parsed. Verified: 3 checks pass.

Fixes #1641


Support my work: If this fix helped, consider buying me a coffee at https://buymeacoffee.com/muhamedfazalps

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 httpie#1641
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_lazy_choices_help fails on Python 3.14

1 participant