-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Less restricted type expansion, more robust subcommand matching, impr…
…oved error messages (#204) * Improve mismatched type for StrEnum * Overhaul subcommand matching * Additional subcommand matching tests * Min 3.11 for StrEnum tests * fix test ignore * Test nits * typeguard compatibility * Add minimum typeguard version * fix typeguard errors * typeguard refactor, more subcommand matching tests * Add 3.13 to CI (fixes #206) * Add pydantic version exclude, waiting for patch Related: pydantic/pydantic#10912, pydantic/pydantic#10909 * Improve type warnings + errors * Generic subcommand example, docs updates * Remove unused * `build` => `pytest`, closes #206 * mypy
- Loading branch information
Showing
36 changed files
with
875 additions
and
262 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# mypy: ignore-errors | ||
# | ||
# Passing a Union type directly to tyro.cli() doesn't type-check correctly in | ||
# mypy. This will be fixed by `typing.TypeForm`: https://peps.python.org/pep-0747/ | ||
"""Generic Subcommands | ||
Usage: | ||
python ./03_generic_subcommands.py --help | ||
python ./03_generic_subcommands.py experiment-adam --help | ||
python ./03_generic_subcommands.py experiment-sgd --help | ||
python ./03_generic_subcommands.py experiment-adam --path /tmp --lr 1e-3 | ||
""" | ||
|
||
import dataclasses | ||
from pathlib import Path | ||
|
||
import tyro | ||
|
||
|
||
@dataclasses.dataclass | ||
class Sgd: | ||
lr: float = 1e-4 | ||
|
||
|
||
@dataclasses.dataclass | ||
class Adam: | ||
lr: float = 3e-4 | ||
betas: tuple[float, float] = (0.9, 0.999) | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class Experiment[OptimizerT: (Adam, Sgd)]: | ||
path: Path | ||
opt: OptimizerT | ||
|
||
|
||
if __name__ == "__main__": | ||
args = tyro.cli(Experiment[Adam] | Experiment[Sgd]) | ||
print(args) |
Oops, something went wrong.