Skip to content

Commit

Permalink
Use expanduser() on Path arguments/options
Browse files Browse the repository at this point in the history
  • Loading branch information
pmav99 committed Mar 29, 2021
1 parent c3a4c72 commit 6c5de1f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pathlib

from typer import main


def test_param_path_convertor() -> None:
assert main.param_path_convertor(None) is None
assert main.param_path_convertor("/foo") == pathlib.Path("/foo")
# check that expanduser has been called.
# If we start to run tests on windows, we will probably need to update this
assert main.param_path_convertor("~/foo").to_posix().startswith("/")
2 changes: 1 addition & 1 deletion typer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ def get_command_from_info(command_info: CommandInfo) -> click.Command:

def param_path_convertor(value: Optional[str] = None) -> Optional[Path]:
if value is not None:
return Path(value)
return Path(value).expanduser()
return None


Expand Down

0 comments on commit 6c5de1f

Please sign in to comment.