You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Now I would like to make some-string parameter optional:
classMySpec(BaseModel):
some_set: Set[int] =Field(
default={1, 2, 3},
decsription="Some set of integers",
title="Some set",
)
some_string: Optional[str] =Field(
decsription="Some string without a default value.",
title="SomeSTR",
)
Everything still works, but with a warning:
$ python3.11 example.py --help
/usr/local/lib/python3.11/site-packages/tyro/_fields.py:181: UserWarning: The field some_string is annotated with type <class 'str'>, but the default value None has type <class 'NoneType'>. We'll try to handle this gracefully, but it may cause unexpected behavior.
warnings.warn(
usage: example.py [-h] [--spec.some-set [INT [INT ...]]] [--spec.some-string {None}|STR]
╭─ options ─────────────────────────────────────────╮
│ -h, --help show this help message and exit │
╰───────────────────────────────────────────────────╯
╭─ spec options ────────────────────────────────────╮
│ --spec.some-set [INT [INT ...]] │
│ (default: '{1, 2, 3}') │
│ --spec.some-string {None}|STR │
│ (default: None) │
╰───────────────────────────────────────────────────╯
I am not quite sure why there is a warning as some-string is declared as union of "None" and "str", having "None" as default value should be legal.
Moreover, when I try to suppress an optional option, no suppression is made at all:
classMySpec(BaseModel):
some_set: Set[int] =Field(
default={1, 2, 3},
decsription="Some set of integers",
title="Some set",
)
some_string: tyro.conf.Suppress[Optional[str]] =Field(
decsription="Some string without a default value.",
title="SomeSTR",
)
$ python3.11 example.py --help
/usr/local/lib/python3.11/site-packages/tyro/_fields.py:181: UserWarning: The field some_string is annotated with type <class 'str'>, but the default value None has type <class 'NoneType'>. We'll try to handle this gracefully, but it may cause unexpected behavior.
warnings.warn(
usage: example.py [-h] [--spec.some-set [INT [INT ...]]] [--spec.some-string {None}|STR]
╭─ options ─────────────────────────────────────────╮
│ -h, --help show this help message and exit │
╰───────────────────────────────────────────────────╯
╭─ spec options ────────────────────────────────────╮
│ --spec.some-set [INT [INT ...]] │
│ (default: '{1, 2, 3}') │
│ --spec.some-string {None}|STR │
│ (default: None) │
╰───────────────────────────────────────────────────╯
Suppression is ignored even when I remove warning by setting default value of type str.
Suppresion works, when Optional is not used, or when I prefix option name with _.
The text was updated successfully, but these errors were encountered:
Hi @KrobotP, can you confirm which version of pydantic you're using?
This:
fromtypingimportOptional, SetfrompydanticimportBaseModel, FieldimporttyroclassMySpec(BaseModel):
some_set: Set[int] =Field(
default={1, 2, 3},
decsription="Some set of integers",
title="Some set",
)
some_string: tyro.conf.Suppress[Optional[str]] =Field(
decsription="Some string without a default value.",
title="SomeSTR",
)
tyro.cli(MySpec)
appears to give me the right behavior with pydantic==2.9.2; an error that some_string is missing a default value. When I set the default value, the error disappears and the argument is correctly suppressed.
As a note, it seems like you've also misspelled description in all of your examples.
Hello @brentyi, I am currently using older version (1.2) as we are in the middle of transfer to the newer 2+. Thus, we wuld like to work with both versions for some time.
Once more I am here with my example app:
Everything works fine here:
Now I would like to make
some-string
parameter optional:Everything still works, but with a warning:
I am not quite sure why there is a warning as
some-string
is declared as union of "None" and "str", having "None" as default value should be legal.Moreover, when I try to suppress an optional option, no suppression is made at all:
Suppression is ignored even when I remove warning by setting default value of type
str
.Suppresion works, when
Optional
is not used, or when I prefix option name with_
.The text was updated successfully, but these errors were encountered: