Skip to content

Commit

Permalink
Add code to copy instance methods from original original class defini…
Browse files Browse the repository at this point in the history
…tion to Pydantic model.
  • Loading branch information
deanpoulos committed Jan 23, 2025
1 parent e169085 commit 3af1e56
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions qualibrate/q_runnnable.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,12 @@ def build_parameters_class_from_instance(
__module__=parameters.__class__.__module__,
**{name: (info.annotation, info) for name, info in fields.items()},
)

# Copy methods from the original class
for method_name, method in parameters.__class__.__dict__.items():
if callable(method) and not method_name.startswith('__'):
setattr(model, method_name, method)

if hasattr(parameters, "targets_name"):
model.targets_name = parameters.targets_name
return cast(type[CreateParametersType], model)
Expand Down

0 comments on commit 3af1e56

Please sign in to comment.