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
When parsing a parameter that is a Union of types, there are some deficiencies in the parsing. I am borrowing from the bug report at #588. By adding a field with the class name, I can successfully parse all Union types:
from dataclasses import dataclass
from jsonargparse import CLI
@dataclass
class A:
A: bool
foo: int = 3
@dataclass
class B:
B: bool
foo: int = 3
bar: float = 1.0
def func(params: A | B):
print(params)
if __name__ == "__main__":
CLI(func)
We can now choose the class to parse like so (would be even nicer with a store-false type):
python myscript.py --params.A=true
However, it is not possible to get help for the type chosen, which severly limits the user's ability to actually use it. It would make it more usable if writing:
python myscript.py --params.A=true --help
would print the help for type A.
Motivation
Enable parsing of Union types including a verbose help.
This is related to #588. While the hack above solves the parsing itself, it is extremely limited if the user cannot get the help he needs for the chosen type.
Pitch
If there is a way to get help for the chosen type by writing something like:
python myscript.py --params.A=true --help
This would be good enough to support union types flawlessly.
Alternatives
The text was updated successfully, but these errors were encountered:
As mentioned in #588 (comment), which points to #287 (comment), the plan is to make dataclasses behave like subclasses. Actually this proposal seems to be a duplicate of #368, where I explain the help behavior, see #368 (comment). It would not be as you propose, but like python myscript.py --params.help A.
I have already spent a lot of time on an implementation for #287, but it still requires considerable work and take time. I will think about the possibility of adding the help part for dataclasses without the full subclass support. But I would only do that if it is not a significant additional effort.
Thanks for this.
As I am new to jsonargsparse I missed the key point that everything I want to achieve is readily available if I use regular classes and subclasses instead of dataclasses. For me this compromise is acceptable.
🚀 Feature request
When parsing a parameter that is a Union of types, there are some deficiencies in the parsing. I am borrowing from the bug report at #588. By adding a field with the class name, I can successfully parse all Union types:
We can now choose the class to parse like so (would be even nicer with a store-false type):
However, it is not possible to get help for the type chosen, which severly limits the user's ability to actually use it. It would make it more usable if writing:
would print the help for type A.
Motivation
Enable parsing of Union types including a verbose help.
This is related to #588. While the hack above solves the parsing itself, it is extremely limited if the user cannot get the help he needs for the chosen type.
Pitch
If there is a way to get help for the chosen type by writing something like:
This would be good enough to support union types flawlessly.
Alternatives
The text was updated successfully, but these errors were encountered: