Skip to content

🐛 Ensure that an envvar set for a typer.Option list is split on whitespace#1791

Merged
tiangolo merged 3 commits into
fastapi:masterfrom
svlandeg:fix/envvar-list
May 27, 2026
Merged

🐛 Ensure that an envvar set for a typer.Option list is split on whitespace#1791
tiangolo merged 3 commits into
fastapi:masterfrom
svlandeg:fix/envvar-list

Conversation

@svlandeg
Copy link
Copy Markdown
Member

@svlandeg svlandeg commented May 26, 2026

Fixes #1789, thanks to @wpk-nist-gov for the report.

Description

This bug fix is related to #1787 though not quite the same. A user reported that this doesn't work anymore:

def from_option(user: Annotated[list[str], typer.Option(envvar="ME")]):
    print(f"Hello {user}")

As far as I know, we don't actually document using envvar in combination with a list type. Before 0.26.0, Click's defaults would parse the envvar string on whitespace and produce a list when calling this with something like env={"ME": "rick morty"}.

This currently still works for Argument as it doesn't have its own implementation of value_from_envvar, it still uses Click's old one from Parameter. For Option, this functionality was removed in the refactor. This PR restores the functionality for Option in a quick bug fix PR. Argument and Option should work similarly, which is now the case with this PR. For the future, we should consider whether we want to keep & document this behaviour.

AI Disclaimer

Used Cursor to help me debug the issue more quickly, manually reviewed everything in detail.

Checklist

  • I added tests for the change.
  • The new or updated tests fail on the main branch and pass on this PR.
  • Coverage stays at 100%.

@svlandeg svlandeg added the bug Something isn't working label May 26, 2026
@svlandeg svlandeg marked this pull request as ready for review May 26, 2026 19:15
@wpk-nist-gov
Copy link
Copy Markdown

For what it's worth, this behavior is documented for click (which is where I got the idea from). Thanks again for your help @svlandeg!

@svlandeg
Copy link
Copy Markdown
Member Author

svlandeg commented May 26, 2026

For what it's worth, this behavior is documented for click (which is where I got the idea from).

Yes, but the point is that it's not documented for Typer. And going forward after the vendoring, only what is documented by Typer is considered to be part of Typer's public API. So, if this is a feature we want to explicitly support and test, we should also document it.

(But that's considered follow-up work & decisions as we have tried to be as minimally breaking for now)

Copy link
Copy Markdown
Member

@tiangolo tiangolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to do this for now to keep the changes from the migration minimal, thank you! 🚀

This will be available in Typer 0.26.2 in the next few hours.


About deciding to keep it for the future or not, I'm undecided yet, as I suspect we'll refactor a bunch of this logic when we re-work how types work. For now, let's delay that decision for later.

@tiangolo tiangolo merged commit 5568bab into fastapi:master May 27, 2026
22 checks passed
@svlandeg svlandeg deleted the fix/envvar-list branch May 27, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants