-
-
Notifications
You must be signed in to change notification settings - Fork 59
Closed
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancementNew feature or requestNew feature or request
Description
🐛 Bug report
CLI
fails to instantiate pydantic
classes.
To reproduce
In main.py
:
import jsonargparse
import pydantic
class MyClass1(pydantic.BaseModel):
a: int
class MyClass2(pydantic.BaseModel):
b: int
def func(instance: pydantic.BaseModel) -> None:
print(instance)
if __name__ == "__main__":
jsonargparse.CLI(func)
In config.yaml
:
instance:
class_path: __main__.MyClass1
init_args:
a: 1
In terminal:
python -m main --config config.yaml
Expected behavior
Program should exit with zero code.
It does work If I change pydantic
classes to normal classes.
Environment
- jsonargparse version (e.g., 4.8.0): 4.28.0
- pydantic version: 2.7.1
- Python version (e.g., 3.9): 3.9.19
- How jsonargparse was installed (e.g.
pip install jsonargparse[all]
):pip install jsonargparse[all]
- OS (e.g., Linux): macOS
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existsenhancementNew feature or requestNew feature or request