feat(extras): add Verbosity type for -v/-q count flags#445
Merged
brentyi merged 7 commits intobrentyi:mainfrom Mar 31, 2026
Merged
feat(extras): add Verbosity type for -v/-q count flags#445brentyi merged 7 commits intobrentyi:mainfrom
brentyi merged 7 commits intobrentyi:mainfrom
Conversation
Adds tyro.extras.Verbosity, a frozen dataclass that wires up mutually exclusive --verbose/-v and --quiet/-q count flags and exposes a log_level() method mapping them to Python logging levels. Inspired by clap-verbosity-flag from the Rust/clap ecosystem.
ac49aae to
968d933
Compare
Owner
|
Hi @jRimbault thanks for taking the time to make this PR, and also for your nice words! This feels generally useful enough to include in |
jRimbault
added a commit
to jRimbault/fixture-graph
that referenced
this pull request
Mar 30, 2026
Adapted from tyro PR #445 (brentyi/tyro#445). Provides a Verbosity dataclass that maps counter flags to Python logging levels.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following up on our Reddit thread, here's the actual proposal.
We have a
Verbositydataclass we keep reusing across internal tools (we've already packaged it internally to not repeat ourselves though, so this doesn't need to be upstreamed, I just think it'd be nice in the ecosystem). It bundles mutually exclusive--verbose/-vand--quiet/-qcount flags and exposes alog_level()method mapping them to Pythonlogginglevels. Since it's built onUseCounterActionandcreate_mutex_group, it's entirely composed from existing tyro primitives.Usage
OmitArgPrefixespromotes the flags to the top level (--verbose,--quiet). Without it, they're prefixed as usual (--verbosity.verbose,--verbosity.quiet), but the-v/-qshort aliases always work regardless.Default level mapping (baseline:
WARNING):-v-vv-q-qqValues are clamped to
DEBUG..CRITICAL.Prior art
The pattern is borrowed from
clap-verbosity-flag, maintained by the clap maintainers, which provides the same type for Rust CLIs.A few things I'm unsure about before you review:
tyroitself? Or would you rather that I make a third party package kinda like the clap ecosystemtyro.extrasis the right home, or if it belongs closer totyro.confOmitArgPrefixesinto the type automatically (via a custom struct rule) would be preferred over leaving it explicitHappy to adjust either. Let me know what you think.
Loving the library by the way, it's a staple in our internal tooling.