Overriding a config's argument makes everything else fall back to the base class
carmocca opened this issue · comments
🐛 Bug report
To reproduce
repro.py
:
from dataclasses import dataclass
from typing import Optional
@dataclass
class Thing:
foo: int = 1
bar: int = 2
def fn(thing: Optional[Thing] = None):
thing = Thing() if thing is None else thing
print(thing)
from jsonargparse import CLI
CLI(fn)
repro.yaml
:
thing:
foo: 123
bar: 321
python repro.py --config repro.yaml --thing.foo 9
Expected behavior
The above prints
Thing(foo=9, bar=2)
but I expected
Thing(foo=9, bar=321)
Context
A more real world example is that you have a trainer_config.yaml
and you want to only modify the --train.max_epochs
value without having everything else fall back to dataclass defaults
Environment
Version 4.275
Given that
class Thing:
def __init__(self, foo=1, bar=2):
print(locals())
from jsonargparse import CLI
CLI(Thing)
foo: 123
bar: 321
python repro.py --config repro.yaml --foo 9
Works as expected, I would expect these two approaches to produce the same result
Thank you for reporting! This is fixed with #471.