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
I wonder if OmegaConf could be refactored so that adding support for a new, custom node type would be as simple as calling e.g. OmegaConf.register_custom_node_type(MyPathNode, pathlib.Path). This would be a step in the direction of enabling 3rd party packages to provide support for custom node types (pip install omegaconf-pathlib).
Background:
OmegaConf implements support for a core set of data types. For example:
While supporting common use-cases is a goal of OmegaConf, there are also risks involved with taking on many new node types:
maintenance burden
feature bloat
Some of the above node types are easier to implement than others. In the simplest case, support for a new leaf node type (such e.g. pathlib.Path) requires changing OmegaConf's source code in two places:
define a new subclass of ValueNode must be defined (e.g. class PathNode(ValueNode): ...).
Extend the switch statement in _node_wrap to handle the new type.
A simple case such as this could be handled by a OmegaConf.register_custom_node_type method, enabling extension as described in the introduction above.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Idea:
I wonder if OmegaConf could be refactored so that adding support for a new, custom node type would be as simple as calling e.g.
OmegaConf.register_custom_node_type(MyPathNode, pathlib.Path)
. This would be a step in the direction of enabling 3rd party packages to provide support for custom node types (pip install omegaconf-pathlib
).Background:
OmegaConf implements support for a core set of data types. For example:
StringNode
handles data typed asstr
IntegerNode
handles data typed asint
AnyNode
handles untyped leaf-node data (and data typed asAny
)We have several open feature requests and PRs looking to expand the set of supported node types. Here is a (possibly-incomplete) list:
bytes
(Havebytes
as supported value type. #844 and Include support for bytes built-in type. #872)pathlib.Path
(Add support for pathlib.Path type #97 and add pathlib.Path support #873)datetime.datetime
(Needdatetime
-typed field support #851)typing.Literal
(Allow the use of typing.Literal as a pythonic alternative to Enums #422 and Adds literal node #865)typing.Union
(Look into supporting Union in Structured configs #144)tuple
(Improve Tuple support #392)While supporting common use-cases is a goal of OmegaConf, there are also risks involved with taking on many new node types:
Some of the above node types are easier to implement than others. In the simplest case, support for a new leaf node type (such e.g.
pathlib.Path
) requires changing OmegaConf's source code in two places:ValueNode
must be defined (e.g.class PathNode(ValueNode): ...
)._node_wrap
to handle the new type.A simple case such as this could be handled by a
OmegaConf.register_custom_node_type
method, enabling extension as described in the introduction above.Beta Was this translation helpful? Give feedback.
All reactions