Skip to content

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

@Nhfiam

Description

@Nhfiam

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(

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions