Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assertion won't be formatted correctly in _arguments #28

Open
tovacinni opened this issue Dec 30, 2022 · 1 comment
Open

Assertion won't be formatted correctly in _arguments #28

tovacinni opened this issue Dec 30, 2022 · 1 comment

Comments

@tovacinni
Copy link

Sorry for the issue spamming- but here's a small bug report that this assertion needs to be replaced by an Exception to properly display which fields have issues in the defaults. I would submit a PR but I'll probably get the type of Exception to use wrong :D

tyro/tyro/_arguments.py

Lines 198 to 201 in e88e690

assert False, (
"Expected a boolean as a default for {arg.field.name}, but got"
" {lowered.default}."
)

brentyi added a commit that referenced this issue Dec 30, 2022
@brentyi
Copy link
Owner

brentyi commented Dec 30, 2022

Aha thanks! Partially addressed this by fixing the broken f-string, so the assertion error should be useful now.

Need to think about whether this should be converted to an exception.
I'm leaning slightly toward keeping it as an assert because (1) it doesn't seem like it would ever need to be caught, (2) code that causes this problem would usually be flagged by a type checker*, and (3) none of the existing custom exceptions (unsupported type annotations, instantiation errors, unsupported nested type errors, etc) seem like a good fit.

*I understand this isn't the case if you're dynamically reading defaults from a YAML. But I'm not sure it's tyro's responsibility if you have a field annotated as bool which actually contains a string. Egregious example:

import tyro


def main(x: bool = "False") -> None:
    pass


tyro.cli(main)  # Should trigger the same error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants