Skip to content

Commit

Permalink
Docs formatting fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brentyi committed May 16, 2023
1 parent 3de5c7f commit aa5d187
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
17 changes: 11 additions & 6 deletions tyro/extras/_base_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ def subcommand_type_from_defaults(
]
```
Direct use of `typing.Union` and `tyro.conf.subcommand()` should generally be
preferred, but this function can be helpful for succinictness.
Direct use of `typing.Union` and :func:`tyro.conf.subcommand()` should generally be
preferred, but this function can be helpful for succinctness.
.. warning::
The type returned by this function can be safely used as an input to
`tyro.cli()`, but for static analysis when used for annotations we recommend
applying a TYPE_CHECKING guard:
:func:`tyro.cli()`, but for static analysis when used for annotations we
recommend applying a `TYPE_CHECKING` guard:
.. code-block:: python
Expand All @@ -61,6 +59,13 @@ def subcommand_type_from_defaults(
# Runtime type used by tyro.
SelectableConfig = subcommand_type_from_defaults(...)
Args:
defaults: A dictionary of default subcommand instances.
descriptions: A dictionary conttaining descriptions for helptext.
prefix_names: Whether to prefix subcommand names.
Returns:
A subcommand type, which can be passed to :func:`tyro.cli`.
"""
return Union.__getitem__( # type: ignore
tuple(
Expand Down
12 changes: 8 additions & 4 deletions tyro/extras/_choices_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ def literal_type_from_choices(choices: Iterable[T]) -> TypeForm[T]:
Using `Literal[...]` directly should generally be preferred, but this function can be
helpful when choices are generated dynamically.
.. warning::
The type returned by this function can be safely used as an input to
`tyro.cli()`, but for static analysis when used for annotations we recommend
applying a TYPE_CHECKING guard:
:func:`tyro.cli()`, but for static analysis when used for annotations we
recommend applying a `TYPE_CHECKING` guard:
.. code-block:: python
Expand All @@ -31,5 +29,11 @@ def literal_type_from_choices(choices: Iterable[T]) -> TypeForm[T]:
else:
# Runtime type used by tyro.
Color = literal_type_from_choices(["red", "green", "blue"])
Args:
choices: Options to choose from.
Returns:
A type that can be passed to :func:`tyro.cli()`.
"""
return Literal.__getitem__(tuple(choices)) # type: ignore

0 comments on commit aa5d187

Please sign in to comment.