Skip to content

PEP 604 Support #348

@AngellusMortis

Description

@AngellusMortis

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from pathlib import Path
import typer


def main(output: Path | None):
    typer.guess_name(f"Hello {name}")


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

Description

Using an argument with the type of pathlib.Path | None (as per PEP 604) raise the error:

Type not yet supported: pathlib.Path | None

Wanted Solution

| None types should work instead of having to need to use Optional[].

Wanted Code

from pathlib import Path
import typer


def main(output: Path | None):
    typer.echo(output)


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

Alternatives

No response

Operating System

Linux

Operating System Details

No response

Typer Version

0.4.0

Python Version

3.10.1

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions