I was trying to write a click option argument with type=click.Choice((“North”, 
“South”, “West”, “East”)) and I also like to annotate the function itself for 
documentation (even though I call it without passing arguments). Something like 
the the following..

@click.command()
@click.option(“--direction”, type=click.Choice((“North”, “South”, “West”, 
“East”)), default=“North”)
def main(direction: “North” | “South” | “West” | “East” = “North”) -> None:
    print(direction) 

> On 5 Feb 2022, at 11:21 PM, Abdulla Al Kathiri <alkathiri.abdu...@gmail.com> 
> wrote:
> 
> Hello all, 
> 
> Why can’t we use the literals directly as types? For example, 
> 
> x: Literal[1, 2, 3] = 3 
> name: Literal[“John”] | None = “John"
> 
> Become …. 
> 
> x: 1 | 2 | 3 = 3 
> name: “John” | None = “John"
> 
> 
> def open(file: Path | str, mode: “w” | “a” = “w”): … 
> 
> Best Regards, 
> 
> Abdulla

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/BSEPQBJRQDDIII2VXYPMKKW74V22XEKT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to