Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/test_coercion.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,20 @@ def test_plugin_when_previously_set(
with disabled_pydantic_plugins():
assert os.environ["PYDANTIC_DISABLE_PLUGINS"] == "1"
assert os.environ["PYDANTIC_DISABLE_PLUGINS"] == "0"


def test_coercion_path_allow_dash() -> None:
app = typer.Typer()
seen: list[Path] = []

@app.command()
def main(
config: Path = typer.Option(
..., exists=True, resolve_path=True, allow_dash=True
),
):
seen.append(config)

result = runner.invoke(app, ["--config", "-"])
assert result.exit_code == 0, result.output
assert seen == [Path("-")]
4 changes: 3 additions & 1 deletion typer/_param_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ def coerce_cli_path(
raise BadParameter(get_error_msg(exc), ctx=ctx, param=param) from exc

is_dash = (
parameter_info.file_okay and parameter_info.allow_dash and rv in (b"-", "-")
parameter_info.file_okay
and parameter_info.allow_dash
and os.fspath(rv) in (b"-", "-")
)

if not is_dash:
Expand Down
Loading