diff --git a/tests/test_others.py b/tests/test_others.py index b389ed353f..40fd9f8fd8 100644 --- a/tests/test_others.py +++ b/tests/test_others.py @@ -94,6 +94,18 @@ def main(): assert "Hello World" in result.stdout +def test_option_envvar_accepts_sequence_tuple(): + app = typer.Typer() + + @app.command() + def main(name: str = typer.Option(..., envvar=("TEST_NAME", "ALT_TEST_NAME"))): + typer.echo(name) + + result = runner.invoke(app, [], env={"ALT_TEST_NAME": "Camila"}) + assert result.exit_code == 0 + assert "Camila" in result.stdout + + def test_callback_too_many_parameters(): app = typer.Typer() diff --git a/typer/core.py b/typer/core.py index 48fee64e34..4ef9fb6d3a 100644 --- a/typer/core.py +++ b/typer/core.py @@ -261,7 +261,7 @@ def __init__( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ @@ -412,7 +412,7 @@ def __init__( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ diff --git a/typer/models.py b/typer/models.py index 3285a96a24..a458602961 100644 --- a/typer/models.py +++ b/typer/models.py @@ -282,7 +282,7 @@ def __init__( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ @@ -391,7 +391,7 @@ def __init__( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ @@ -519,7 +519,7 @@ def __init__( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ diff --git a/typer/params.py b/typer/params.py index b325b273c4..c803942d72 100644 --- a/typer/params.py +++ b/typer/params.py @@ -1,4 +1,4 @@ -from collections.abc import Callable +from collections.abc import Callable, Sequence from typing import TYPE_CHECKING, Annotated, Any, overload import click @@ -20,7 +20,7 @@ def Option( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ @@ -85,7 +85,7 @@ def Option( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ @@ -246,7 +246,7 @@ def main(user: Annotated[str, typer.Option(metavar="User name")]): ), ] = False, envvar: Annotated[ - str | list[str] | None, + str | Sequence[str] | None, Doc( """ Configure a CLI Option to read its value from an environment variable if it is not provided in the command line. @@ -1010,7 +1010,7 @@ def Argument( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ @@ -1066,7 +1066,7 @@ def Argument( metavar: str | None = None, expose_value: bool = True, is_eager: bool = False, - envvar: str | list[str] | None = None, + envvar: str | Sequence[str] | None = None, # Note that shell_complete is not fully supported and will be removed in future versions # TODO: Remove shell_complete in a future version (after 0.16.0) shell_complete: Callable[ @@ -1200,7 +1200,7 @@ def main(name: Annotated[str, typer.Argument(metavar="✨username✨")]): ), ] = False, envvar: Annotated[ - str | list[str] | None, + str | Sequence[str] | None, Doc( """ Configure an argument to read a value from an environment variable if it is not provided in the command line as a CLI argument.