Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sofie Van Landeghem · committed by GitHub · parent 8c70d49 · Browse files · 2 files+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−1 removed

  • tests:+15 added−1 removed
  • other:+5 added−0 removed

2 files+20 added−1 removed

modified:tests/test_others.py+15 added-1 removed
323 unmodified lines
324 result = runner.invoke(app)325 assert "[]" in result.output326327328def test_option_uses_envvar_when_required():328def test_option_envvar():329 app = typer.Typer()330331 @app.command()332 def main(user: Annotated[str, typer.Option(envvar="ME")]):
3 unmodified lines
336 assert result.exit_code == 0337 assert "Hello rick" in result.output338339340def test_option_envvar_list():341 app = typer.Typer()342343 @app.command()344 def main(users: Annotated[list[str], typer.Option(envvar="ME")]):345 for u in users:346 print(f"Hello {u}")347348 result = runner.invoke(app, env={"ME": "rick morty"})349 assert result.exit_code == 0350 assert "Hello rick" in result.output351 assert "Hello morty" in result.output352353354def test_completion_argument():355 file_path = Path(__file__).parent / "assets/completion_argument.py"356 result = subprocess.run(357 [sys.executable, "-m", "coverage", "run", str(file_path), "E"],
130 unmodified lines
modified:typer/core.py+5 added
665 unmodified lines
666 **prompt_kwargs,667 )668669 def value_from_envvar(self, ctx: _click.Context) -> Any:670 # TODO: clean up671 rv = self.resolve_envvar_value(ctx)672673 # Absent environment variable or an empty string is interpreted as unset.674 if rv is None:675 return None676677 if self.nargs != 1 or self.multiple:678 return self.type.split_envvar_value(rv)679680 return rv681682 def resolve_envvar_value(self, ctx: _click.Context) -> str | None:683 rv = super().resolve_envvar_value(ctx)
532 unmodified lines