Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken message about invalid argument value for template "File ... is a directory" #2697

Open
Nhfiam opened this issue Mar 30, 2024 · 0 comments

Comments

@Nhfiam
Copy link

Nhfiam commented Mar 30, 2024

User Actions

mkdir $'my\ndir'
my-tool $'my\ndir'

Expected Output

Invalid value for 'PATH': File 'my\ndir' is a directory.

Actual Output

Invalid value for 'PATH': File 'my
dir' is a directory.

Code

from pathlib import Path
from typing import Annotated

import typer


def main(path: Annotated[Path, typer.Argument(dir_okay=False)]) -> None:
    pass


if __name__ == '__main__':
    typer.run(main)

Cause
You clearly forgot !r on this line and are using quotes instead.

Just compare these lines in click.types:

_("{name} {filename!r} does not exist.").format(
_("{name} {filename!r} is a file.").format(
_("{name} '{filename}' is a directory.").format(
_("{name} {filename!r} is not readable.").format(
_("{name} {filename!r} is not writable.").format(
_("{name} {filename!r} is not executable.").format(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant