From d64bade7c13a8313bb8735d9680bf65c17f01319 Mon Sep 17 00:00:00 2001 From: Anubhav Date: Tue, 10 Nov 2026 20:47:03 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20allow=5Fdash=20for=20Path?= =?UTF-8?q?=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_coercion.py | 17 +++++++++++++++++ typer/_param_types.py | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) 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: