🐛 Bug report
Cannot instantiate a class from env variables.
To reproduce
In main.py:
from jsonargparse import CLI
class Bar:
def __init__(self, v: int) -> None:
self._v = v
def main(b: Bar) -> None:
print(b._v)
if __name__ == "__main__":
CLI(main, default_env=True, env_prefix="FOO")
In shell:
export FOO_B__V=2
python -m main
Will result in the error:
usage: main.py [-h] [--config CONFIG] [--print_config[=flags]] [--b.help [CLASS_PATH_OR_NAME]] b
error: Validation failed: Key "b" is required but not included in config object or its value is None.
I can instantiate this class with:
export FOO_B="{v: 1}"
python -m main
But I cannot even override v:
export FOO_B__V=2
python -m main
Will still result in v being 1.
Expected behavior
I can instantiate a class from env variables. At least override fields.
Environment
- jsonargparse version: 4.37.0
- Python version: 3.12.8
- How jsonargparse was installed:
uv pip install -U "jsonargparse[all]"
- OS: macOS
🐛 Bug report
Cannot instantiate a class from env variables.
To reproduce
In
main.py:In shell:
export FOO_B__V=2 python -m mainWill result in the error:
I can instantiate this class with:
But I cannot even override
v:export FOO_B__V=2 python -m mainWill still result in
vbeing 1.Expected behavior
I can instantiate a class from env variables. At least override fields.
Environment
uv pip install -U "jsonargparse[all]"