Skip to content
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

Allow for list[bool] and similar (list of flags). #251

Merged
merged 4 commits into from
Nov 19, 2024

Conversation

BrianPugh
Copy link
Owner

Fixes a bug discovered in #249.

Basically, use should be able to specify list[bool], tuple[bool, ...], Sequence[bool], or Iterable[bool] and be able to accept the flag multiple times. Consider the example:

from cyclopts import App

app = App()

@app.default
def main(
    *,
    verbose: tuple[bool, ...] = (),
):
    verbosity = sum(verbose)
    print(f"{verbosity=}")

if __name__ == "__main__":
    app()

Previously, this would raise an exception at runtime. Now, it handles repeated flags fine:

$ python repeated-flag-demo.py
verbosity=0

$ python repeated-flag-demo.py --verbose
verbosity=1

$ python repeated-flag-demo.py --verbose --verbose
verbosity=2

Copy link

codecov bot commented Nov 16, 2024

Codecov Report

Attention: Patch coverage is 88.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 94.02%. Comparing base (a562380) to head (a16ba52).
Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
cyclopts/_convert.py 25.00% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #251      +/-   ##
==========================================
- Coverage   94.06%   94.02%   -0.05%     
==========================================
  Files          26       26              
  Lines        2949     2961      +12     
  Branches      621      627       +6     
==========================================
+ Hits         2774     2784      +10     
- Misses         84       85       +1     
- Partials       91       92       +1     
Flag Coverage Δ
unittests 94.02% <88.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@BrianPugh BrianPugh merged commit 1d2a550 into main Nov 19, 2024
17 checks passed
@BrianPugh BrianPugh deleted the bugfix/list-of-bool branch November 19, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant