diff --git a/tests/test_coercion.py b/tests/test_coercion.py index 9015c57d92..cd690cdb11 100644 --- a/tests/test_coercion.py +++ b/tests/test_coercion.py @@ -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("-")] diff --git a/typer/_param_types.py b/typer/_param_types.py index 3f6b190a80..e391a45031 100644 --- a/typer/_param_types.py +++ b/typer/_param_types.py @@ -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: