Cannot parse a list of dataclasses with optional dataclass member
mnidza opened this issue · comments
🐛 Bug report
I am getting an when parsing a list of dataclass
objects, where the dataclass
has an optional member which is another dataclass
.
To reproduce
In script.py
from dataclasses import dataclass
from typing import Optional
from jsonargparse import CLI
@dataclass
class A:
x: int
@dataclass
class B:
a: Optional[A] = None
def f(b: list[B]):
print(b)
CLI(f, as_positional=False)
In config.yaml
b:
- a:
x: 1
In terminal
script.py --config config.yaml
Expected behavior
Expected console output
[B(a=A(x=1))]
Actual console output
usage: script.py [-h] [--config CONFIG] [--print_config[=flags]] --b B
error: Validation failed: No action for key "a.x" to set its default.
Environment
- jsonargparse version: 4.29.0
- Python version: 3.11.4
- How jsonargparse was installed:
pip install jsonargparse[signatures]
- OS: Windows 11 Enterprise, 10.0.22631
Thank you for reporting! This is fixed with #527.