From 91dfac237f7cd962b57fd41ce4e0db0b68423630 Mon Sep 17 00:00:00 2001 From: brentyi Date: Sun, 17 Nov 2024 23:46:53 -0500 Subject: [PATCH] `0.9.0` --- docs/source/examples/custom_constructors.rst | 11 ++++++++--- docs/source/examples/hierarchical_structures.rst | 4 ++-- docs/source/whats_supported.rst | 2 +- .../03_nesting_containers.py | 4 ++-- examples/06_custom_constructors/README.rst | 11 ++++++++--- pyproject.toml | 2 +- src/tyro/__init__.py | 2 +- 7 files changed, 23 insertions(+), 13 deletions(-) diff --git a/docs/source/examples/custom_constructors.rst b/docs/source/examples/custom_constructors.rst index 38f8ce63..dd8605fd 100644 --- a/docs/source/examples/custom_constructors.rst +++ b/docs/source/examples/custom_constructors.rst @@ -6,9 +6,9 @@ Custom constructors =================== -:func:`tyro.cli` is designed for comprehensive support of standard Python type -constructs. In some cases, however, it can be useful to extend the set of types -supported by :mod:`tyro`. +:func:`tyro.cli` aims for comprehensive support of standard Python type +constructs. It can still, however, be useful to extend the set of suported +types. We provide two complementary approaches for doing so: @@ -19,6 +19,11 @@ We provide two complementary approaches for doing so: instantiated from a single commandline argument, while *struct* types are broken down into multiple arguments. +.. warning:: + + Custom constructors are useful, but can be verbose and require care. We + recommend using them sparingly. + .. _example-01_simple_constructors: diff --git a/docs/source/examples/hierarchical_structures.rst b/docs/source/examples/hierarchical_structures.rst index 9c920f0e..67021bde 100644 --- a/docs/source/examples/hierarchical_structures.rst +++ b/docs/source/examples/hierarchical_structures.rst @@ -214,11 +214,11 @@ Structures can be nested inside of standard containers. color_tuple: tuple[RGB, RGB] color_dict: dict[str, RGB] = dataclasses.field( # We can't use mutable values as defaults directly. - default_factory={ + default_factory=lambda: { "red": RGB(255, 0, 0), "green": RGB(0, 255, 0), "blue": RGB(0, 0, 255), - }.copy + } ) if __name__ == "__main__": diff --git a/docs/source/whats_supported.rst b/docs/source/whats_supported.rst index fa05cb2b..f579c40a 100644 --- a/docs/source/whats_supported.rst +++ b/docs/source/whats_supported.rst @@ -9,7 +9,7 @@ As a partial list, inputs can be annotated with: - Basic types like :class:`int`, :class:`str`, :class:`float`, :class:`bool`, :class:`pathlib.Path`, :data:`None`. - :class:`datetime.date`, :class:`datetime.datetime`, and :class:`datetime.time`. - Container types like :class:`list`, :class:`dict`, :class:`tuple`, and :class:`set`. -- Union types, like `X | Y`, :py:data:`typing.Union`, and :py:data:`typing.Optional`. +- Union types, like ``X | Y``, :py:data:`typing.Union`, and :py:data:`typing.Optional`. - :py:data:`typing.Literal` and :class:`enum.Enum`. - Type aliases, for example using Python 3.12's `PEP 695 `_ `type` statement. - Generics, such as those annotated with :py:class:`typing.TypeVar` or with the type parameter syntax introduced by Python 3.12's `PEP 695 `_. diff --git a/examples/02_hierarchical_structures/03_nesting_containers.py b/examples/02_hierarchical_structures/03_nesting_containers.py index 9f3ecd08..1206be99 100644 --- a/examples/02_hierarchical_structures/03_nesting_containers.py +++ b/examples/02_hierarchical_structures/03_nesting_containers.py @@ -31,11 +31,11 @@ class Args: color_tuple: tuple[RGB, RGB] color_dict: dict[str, RGB] = dataclasses.field( # We can't use mutable values as defaults directly. - default_factory={ + default_factory=lambda: { "red": RGB(255, 0, 0), "green": RGB(0, 255, 0), "blue": RGB(0, 0, 255), - }.copy + } ) diff --git a/examples/06_custom_constructors/README.rst b/examples/06_custom_constructors/README.rst index 23698ee2..277ea3b7 100644 --- a/examples/06_custom_constructors/README.rst +++ b/examples/06_custom_constructors/README.rst @@ -1,9 +1,9 @@ Custom constructors =================== -:func:`tyro.cli` is designed for comprehensive support of standard Python type -constructs. In some cases, however, it can be useful to extend the set of types -supported by :mod:`tyro`. +:func:`tyro.cli` aims for comprehensive support of standard Python type +constructs. It can still, however, be useful to extend the set of suported +types. We provide two complementary approaches for doing so: @@ -13,3 +13,8 @@ We provide two complementary approaches for doing so: for different types. There are two categories of types: *primitive* types are instantiated from a single commandline argument, while *struct* types are broken down into multiple arguments. + +.. warning:: + + Custom constructors are useful, but can be verbose and require care. We + recommend using them sparingly. diff --git a/pyproject.toml b/pyproject.toml index fffa4ffe..54bf2177 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ name = "tyro" authors = [ {name = "brentyi", email = "brentyi@berkeley.edu"}, ] -version = "0.8.14" # TODO: currently needs to be synchronized manually with __init__.py. +version = "0.9.0" # TODO: currently needs to be synchronized manually with __init__.py. description = "Strongly typed, zero-effort CLI interfaces" readme = "README.md" license = { text = "MIT" } diff --git a/src/tyro/__init__.py b/src/tyro/__init__.py index 7be6652a..d21704d5 100644 --- a/src/tyro/__init__.py +++ b/src/tyro/__init__.py @@ -15,4 +15,4 @@ # TODO: this should be synchronized automatically with the pyproject.toml. -__version__ = "0.8.14" +__version__ = "0.9.0"