Skip to content

How to provide default argument values for a function? #447

@Yura52

Description

@Yura52

I have a function where arguments do not have default values. However, I want to generate a CLI for that function with default values for some arguments (for example, based on some config). Something like this:

import json

import tyro


# I don't want this function to have default argument values.
def greet(name: str) -> None:
    print(f'Hello, {name}')


def _load_user_config():
    with open('user_config.json') as f:
        return json.load(f)


if __name__ == '__main__':
    user_config = _load_user_config()
    tyro.cli(greet, defaults={'name': user_config['name']})

Is it possible to achieve this with tyro?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions