Skip to content

[BUG] Path option doesn't seem to expand user #252

Open
@felixgao

Description

@felixgao

Describe the bug

When the path have ~ in the path it doesn't seem to resolve.

To Reproduce

  • Create a file main.py with:
import typer

app = typer.Typer()

@app.command()
def login(
    config_path: Path = typer.Option(
        default=os.environ.get("PROFILE", "~/.aws/my_profile"),
        exists=True,
        file_okay=True,
        dir_okay=False,
        readable=True,
        resolve_path=True,
    )
):
  typer.echo(f"Hello {config_path}")

if __name__ == "__main__":
    app()
  • Call it with:
python main.py
  • It outputs:
Error: Invalid value for '--config-path': File '~/.aws/my_profile' does not exist.
  • But I expected it to output:
Hello ~/.aws/my_profile 

or

Hello /User/username/.aws/my_profile

Environment

  • OS: macOS
  • Typer Version: 0.3.2
  • Python version: 3.6.12

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions