-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
print_config not work correctly when union dataclass-like class #495
Comments
Thank you for reporting this issue and the detailed reproduction code! After a look at it, I don't see any bug. The behavior is working as expected. When the type is
When a union is used, like Even though this is not a bug, it could be considered a feature request. This is closely related to #287. I do have in the roadmap to provide a way to choose which classes should work as subclasses and which not. With this, |
Thanks for your kindly reply! from dataclasses import dataclass
from typing import Union
from jsonargparse import CLI
@dataclass
class DataClass1:
a: str
b: int
@dataclass
class DataClass2:
c: DataClass1
d: str
@dataclass
class DataClass3:
e: DataClass2
f: int
Can |
Yes, this would solve it. |
🐛 Bug report
To reproduce
I have these classes,both
A
andB
are inherited fromBase
,C
is inherited frompydantic.BaseModel
(dataclass-like class):when type hint is
params:Base
we get:
print_config
gives config example rightly when we feed—params
right class (A
/B
/Base
)when type hint is
params:C
(dataclass-like class)we get:
print_config
givesc:c
rightly when--params
feeds nothing--params
feeds any classes (A
/B
/C
)raise exceptionwhen type hint is
Union[A,B,C]
,now I want know how to config params ifisinstance(params,C)
by usingprint_config
we get
no one gives
c:c
config example!Expected behavior
print_config
can printparams
's configEnvironment
pip install jsonargparse[all]
The text was updated successfully, but these errors were encountered: