Skip to content
Discussion options

You must be logged in to vote

I don't think it's possible to make it accept values in quotes - shell (?) strips quotation marks and

python main.py --command "hello,world","goodbye,world"

becomes just

python main.py --command hello,world,goodbye,world

You can improve the solution suggested by @heiskane this way (using callback instead of parser):

from typing import Annotated

import typer

def comma_list(raw: list[str]) -> list[str]:
    return raw[-1].split(",") if (len(raw) > 0) else []

def main(
    command: Annotated[list[str], typer.Option(callback=comma_list)],
):
    print(command)

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

Now command argument is properly typed.

Note: this implementation takes only last…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@YuriiMotov
Comment options

Answer selected by YuriiMotov
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
4 participants
Converted from issue

This discussion was converted from issue #534 on September 19, 2025 12:15.