-
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.0.0] multiparameter is broken #247
Comments
Hi @TakWolf! This change is intentional; from the v3.0.0 changelog:
This change was made because it led to ambiguous/unintuitive CLIs when the user specifies keyword arguments first. Lets expand your example to the following: from typing import Literal
from cyclopts import App
app = App()
@app.default
def main(
font_name: Literal["opensans", "helvetica", "roboto"],
font_sizes: set[Literal[10, 12, 16]] | None = None,
):
print(f"{font_name=} {font_sizes=}")
if __name__ == '__main__':
app() And this works as expected:
In cyclopts v2.9.9, if you specify the # cyclopts v2.9.9
$ python issue-247.py --font-sizes 12 16 roboto
╭─ Error ───────────────────────────────────────────────────────╮
│ Error converting value "roboto" to Literal[10, 12, 16] for │
│ "--font-sizes,--empty-font-sizes". │
╰───────────────────────────────────────────────────────────────╯ So, in v3, cyclopts does the same as other CLI libraries and only consumes one element worth of tokens at a time when specified by keyword: # cyclopts v3.0.0
# same command as before
$ python issue-247.py --font-sizes 12 16 roboto
╭─ Error ───────────────────────────────────────────────────────╮
│ Invalid value for "FONT-NAME": unable to convert "16" into │
│ one of {'opensans', 'helvetica', 'roboto'}. │
╰───────────────────────────────────────────────────────────────╯
# specifying it "correctly" now:
$ python issue-247.py --font-sizes 12 --font-sizes 16 roboto
font_name='roboto' font_sizes={16, 12} If you do not like this new behavior, we can either set from typing import Literal
from cyclopts import App, Parameter
app = App(
default_parameter=Parameter(consume_multiple=True),
)
@app.default
def main(
font_name: Literal["opensans", "helvetica", "roboto"],
font_sizes: set[Literal[10, 12, 16]] | None = None,
):
print(f"{font_name=} {font_sizes=}")
if __name__ == '__main__':
app() EDIT: removed stuff about things not working as expected; it was a local problem to my setup 🙈 |
The following code cannot pass in 3.0.0
The text was updated successfully, but these errors were encountered: