Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Closed
Nhfiam opened this issue Mar 30, 2024 · 1 comment
Milestone

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(
@t-payne
Copy link
Contributor

t-payne commented May 20, 2024

I'm going to work on this at the PyCon 2024 sprints.

@davidism davidism added this to the 8.1.8 milestone May 22, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 7, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants