Skip to content

Commit 6c5de1f

Browse files
committed
Use expanduser() on Path arguments/options
Fixes fastapi#252
1 parent c3a4c72 commit 6c5de1f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

tests/test_main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pathlib
2+
3+
from typer import main
4+
5+
6+
def test_param_path_convertor() -> None:
7+
assert main.param_path_convertor(None) is None
8+
assert main.param_path_convertor("/foo") == pathlib.Path("/foo")
9+
# check that expanduser has been called.
10+
# If we start to run tests on windows, we will probably need to update this
11+
assert main.param_path_convertor("~/foo").to_posix().startswith("/")

typer/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ def get_command_from_info(command_info: CommandInfo) -> click.Command:
446446

447447
def param_path_convertor(value: Optional[str] = None) -> Optional[Path]:
448448
if value is not None:
449-
return Path(value)
449+
return Path(value).expanduser()
450450
return None
451451

452452

0 commit comments

Comments
 (0)