Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
hasattr check in run_with_models
  • Loading branch information
abe-winter committed Jun 13, 2024
commit bbd8c5ba401c1f8e7f75e56ab754a2a829ce0ede
3 changes: 2 additions & 1 deletion src/viam/module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ async def run_with_models(cls, *models: ResourceBase):
args = _parse_module_args()
module = cls(args.socket_path, log_level=args.log_level)
for model in models:
# todo(review): the pyright ignore below is for ResourceBase.MODEL. Is this not a required field? Should I not rely on it?
if not hasattr(model, 'MODEL'):
raise TypeError(f"missing MODEL field on {model}. Resource implementations must define MODEL")
module.add_model_from_registry(model.SUBTYPE, model.MODEL) # pyright: ignore [reportAttributeAccessIssue]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResourceBase does not have a MODEL field at all, since MODELs are for implementation of a ResourceBase, and ResourceBase is for creating the resource definition/interface. This would fail in the possible event that someone passes Arm as the param instead of MyModuleArm

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So would be useful to maybe do a hasattr here and fail if someone doesn't pass the correct type. And also add that disclaimer to the docstring

Copy link
Member Author

@abe-winter abe-winter Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added hasattr check w/ helpful error

I didn't expand docstring because when I started writing it I was saying 'the provided resources have to be complete + runnable' and it felt weird. but can add something if you think it's helpful

await module.start()

Expand Down