Skip to content

Conversation

@libklein
Copy link

@libklein libklein commented Apr 17, 2024

Implements feature #554.

This merge request introduces the functionality to parse List[T] options from strings using a specified separator. An example of how this can be utilized is demonstrated below:

def main(number: List[float] = typer.Option([], multiple_separator=",")):
    print(f"The sum is {sum(number)}")

#  Passing --number 1,2,3 outputs 6  
#  Works with --number 1,2 --number 3 as well. Output would be 6 again.

The implementation works by overwriting the process_value function of the click parser, doing string splitting before forwarding the result to click. This ensures full compatibility with the existing features of both Click and Typer. The feature does not allow whitespace only separators to avoid ambiguities.

Feedback is much appreciated!

Open questions:

  • Currently, error handling is implemented in the constructor of typer.Option, which delays error detection until the command execution. Should we consider moving this error handling to the OptionInfo constructor to allow for earlier failure detection?
    ToDo:
  • Add to doc_src
  • Write tests
  • Update documentation

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@svlandeg
Copy link
Member

Hi, thanks for your PR! I'll put this in draft as long as the test suite is failing.

@svlandeg svlandeg marked this pull request as draft April 18, 2024 08:02
@svlandeg svlandeg added feature New feature, enhancement or request p3 labels Apr 18, 2024
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@libklein libklein marked this pull request as ready for review April 18, 2024 20:11
@github-actions

This comment was marked as outdated.

Copy link
Contributor

@ivantodorovich ivantodorovich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 💚

@github-actions

This comment was marked as outdated.

@libklein libklein force-pushed the multiple-arguments-via-separated-lists branch from 92a6d81 to d5328fa Compare November 30, 2024 18:16
@github-actions

This comment was marked as outdated.

@dylankiss
Copy link

This would be great! Much more convenient to pass a large number of elements to an option 💯
Nice job, @libklein. Hope it will be merged soon 🙏

@misse
Copy link

misse commented Feb 13, 2025

I'd love to use this!

@misse
Copy link

misse commented Feb 13, 2025

@libklein would this work for Enum type choices too?

@dylankiss
Copy link

@tiangolo Little loving nudge ☝️ 😅

@libklein
Copy link
Author

@misse Yes, it is compatible with all of typer's (and click's) features.

@libklein
Copy link
Author

libklein commented Jun 6, 2025

Hi @svlandeg,

more than a year has passed since creating the PR. Are there any updates concerning the roadmap?

@svlandeg svlandeg changed the title ✨ Implement list parsing from string with separators. ✨ Implement list parsing from string with separators Aug 28, 2025
@svlandeg svlandeg self-assigned this Aug 28, 2025
@svlandeg svlandeg marked this pull request as draft August 28, 2025 10:05
@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

@svlandeg
Copy link
Member

Hi @libklein,

I have updated the PR to adhere to the new documentation format, and it is still awaiting further review by Tiangolo. It has been put on our internal review queue. I'd like everyone to refrain from adding additional pings, as that just creates a longer PR thread and generates a lot of noise in our notifications on our end. Instead, if you'd like this PR to be merged, please add an emoticon on the very first post ☝️, which gives us a good idea on how "popular" the idea/PR is.

I do realise it can be a bit frustrating to have this PR sit here for so long. There's just a lot of working in maintaining several open-source repo's (Typer, FastAPI, SQLModel, ...) and we do our best to keep up. Thanks for your understanding! 🙏

Hi @svlandeg,

more than a year has passed since creating the PR. Are there any updates concerning the roadmap?

@svlandeg svlandeg removed their assignment Aug 28, 2025
@svlandeg svlandeg marked this pull request as ready for review August 28, 2025 13:43
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Oct 20, 2025
@github-actions

This comment was marked as resolved.

@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Oct 21, 2025
@github-actions
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature, enhancement or request p3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOC: Documentation of passing multiple values in "option" vs "argument" isn't sufficiently explicit

5 participants