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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for *args arguments in CLI #514

Open
rusmux opened this issue Jun 3, 2024 · 1 comment
Open

Add support for *args arguments in CLI #514

rusmux opened this issue Jun 3, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@rusmux
Copy link

rusmux commented Jun 3, 2024

馃殌 Feature request

Add support for *args arguments in CLI

Motivation

Currently I cannot instantiate *args-like arguments. For example:

In main.py

from jsonargparse import CLI

class A:

    def __init__(self, *a: int, b: int) -> None:
        self.a = a
        self.b = b


def main(a: A) -> None:
    print(a.a, a.b)


if __name__ == '__main__':
    CLI(main)

In config.yaml:

a:
  class_path: __main__.A
  init_args:
    a: [1, 2]
    b: 3

In terminal:

python -m main --config config.yaml

Gives error:

error: Parser key "a":
  Problem with given class_path '__main__.A':
    Validation failed: No action for key "a" to check its value.

Pitch

The above code should runs without errors.

Alternatives

@rusmux rusmux added the enhancement New feature or request label Jun 3, 2024
@mauvilsa
Copy link
Member

mauvilsa commented Jun 9, 2024

Thank you for the proposal! I think about this.

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

No branches or pull requests

2 participants