Skip to content

Commit 26f2c45

Browse files
committed
comments
1 parent 3e6560e commit 26f2c45

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

autointent/_dump_tools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,20 @@ def load( # noqa: PLR0912, C901, PLR0915
171171
content = json.load(file)
172172
variable_name = model_file.stem
173173

174+
# First try to get the type annotation from the class annotations.
174175
model_type = obj.__class__.__annotations__.get(variable_name)
175176

177+
# Fallback: inspect __init__ signature if not found in class-level annotations.
176178
if model_type is None:
177179
sig = inspect.signature(obj.__init__)
178180
if variable_name in sig.parameters:
179181
model_type = sig.parameters[variable_name].annotation
180-
181182
if model_type is None:
182183
msg = f"No type annotation found for {variable_name}"
183184
logger.error(msg)
184185
continue
185186

187+
# If the annotation is a Union, extract the pydantic model type.
186188
if get_origin(model_type) in (UnionType, Union):
187189
for arg in get_args(model_type):
188190
if isinstance(arg, type) and issubclass(arg, BaseModel):

0 commit comments

Comments
 (0)