Skip to content

How to pass a type(not an object) to a class with lightningcli? #14552

Discussion options

You must be logged in to vote

You can change domain_dataset type hint from Dataset to Type:

Here is a demo:

from typing import Type
from jsonargparse import CLI

class Class1:
    def __init__(self) -> None:
        print("Class1")

class Class2:
    def __init__(self) -> None:
        print("Class2")

def test_fn(
    class_type: Type = Class1,
):
    print(class_type)
    class_type()

if __name__ == "__main__":
    CLI(test_fn)
python test.py --class_type '__main__.Class2'

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@calvinzhan
Comment options

Answer selected by calvinzhan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment