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
Is your feature request related to a problem? Please describe.
The return type of a lot of functions in omegaconf is a union of a lot of types, which makes them not very useful. For example, to_object returns a Union with Any, so it's effectively Any.
Describe the solution you'd like
Proof of concept for a generic DictConfig:
fromdataclassesimportdataclassfromtypingimportAny, Dict, Generic, Type, TypeVarT=TypeVar("T")
classDictConfig(Generic[T]):
passclassOmegaConf:
@staticmethoddefstructured(obj: Type[T]) ->DictConfig[T]: # the DictConfig "remembers" the original classraiseNotImplementedError@staticmethoddefcreate(obj: Dict[Any, Any]) ->DictConfig[None]: # not a structured config, so we just say `None`raiseNotImplementedError@staticmethoddefto_object(cfg: DictConfig[T]) ->T: # very precise return typeraiseNotImplementedError@dataclassclassMyConfig:
x: intdefmain() ->None:
d=OmegaConf.structured(MyConfig)
reveal_type(d) # DictConfig[MyConfig]o=OmegaConf.to_object(d)
reveal_type(o) # MyConfig
Describe alternatives you've considered
There might be other solutions to the problem of unspecific return types, but I haven't thought of one yet.
Additional context
None.
The text was updated successfully, but these errors were encountered:
This feature would be grate. I'm using OmegaConf with Metaflow. Being able to parse a config file into a structured (read: correct type) config would eliminate a day or two of wokarounds I need to add.
Is your feature request related to a problem? Please describe.
The return type of a lot of functions in omegaconf is a union of a lot of types, which makes them not very useful. For example,
to_object
returns aUnion
withAny
, so it's effectivelyAny
.Describe the solution you'd like
Proof of concept for a generic
DictConfig
:Describe alternatives you've considered
There might be other solutions to the problem of unspecific return types, but I haven't thought of one yet.
Additional context
None.
The text was updated successfully, but these errors were encountered: