Skip to content

[FEATURE] Pass None / [] / {} to constructor for missing fields when loading engine objectsΒ #1086

@georgeh0

Description

@georgeh0

In load_engine_object() - for loading config object from engine side to Python, when we deal with struct-like types, if the field value is not set, and there's no default value on the Python type, we'll get an error. e.g.

@dataclass
class Type1:
  x: str
  y: Optional[str]

If the value passed from engine doesn't have the y field, our current implementation will call Type1(x='...') which will raise an error as y is missing. But actually it's safe to use None for this case.

We want up update our load_engine_object() to automatically apply the safe default values according to the target type, if a default value isn't provided.

There's an existing _get-auto_default_for_type() method that can be reused to determine if a specific type has a safe default value.


❀️ Contributors, please refer to πŸ“™Contributing Guide.
Unless the PR can be sent immediately (e.g. just a few lines of code), we recommend you to leave a comment on the issue like I'm working on it or Can I work on this issue? to avoid duplicating work. Our Discord server is always open and friendly.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions