You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Seems I was a little too quick to say it works as expected with pure dataclasses. I found one edge cases - when a dataclass parameter is nested inside another dataclass, and it is defined as an Optional field, it requires providing class_path/init_args.
A concrete example -
@dataclass
class Nested:
f1: str = ''
f2: int = 1
@dataclass
class Parent:
fn: Optional[Nested] = None
In the above setup, for the config.yaml for Parent it would have to be
fn:
class_path: Nested
init_args:
f2: 3
If I change Parent making Nested non-Optional, class_path/init_args are no longer needed. If I use the above configuration and do not add class_path/init_args, I get an error like this -
Does not validate against any of the Union subtypes
Subtypes: (<class 'Nested'>, <class 'NoneType'>)
Errors:
- Not a valid Nested
Subclass types expect one of:
- a class path (str)
- a dict with class_path entry
- a dict without class_path but with init_args entry (class path given previously)
- Expected a <class 'NoneType'>
Given value type: <class 'dict'>
@mauvilsa I finally got around to testing this (project was in code-freeze for a while). Seems to working great now, thanks for implementing the clean support for nested optional datalcass parameters.
Seems I was a little too quick to say it works as expected with pure dataclasses. I found one edge cases - when a dataclass parameter is nested inside another dataclass, and it is defined as an
Optional
field, it requires providing class_path/init_args.A concrete example -
In the above setup, for the config.yaml for Parent it would have to be
If I change Parent making Nested non-Optional, class_path/init_args are no longer needed. If I use the above configuration and do not add class_path/init_args, I get an error like this -
Originally posted by @odedbd in #236 (comment)
The text was updated successfully, but these errors were encountered: