From 8e77475b9af43b68e9d072aafb1b200630f25510 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:35:22 +0200 Subject: [PATCH 01/13] Add _resolve_ flag to instantiate. Add _resolve_ flag to instantiate. This is useful for weakly recursive configurations (e.g. instantiate a logger with all the configuration or configuration yaml-string). --- hydra/_internal/instantiate/_instantiate2.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 0406bfd3313..fcade18f863 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -22,6 +22,7 @@ class _Keys(str, Enum): RECURSIVE = "_recursive_" ARGS = "_args_" PARTIAL = "_partial_" + RESOLVE = "_resolve_" def _is_target(x: Any) -> bool: @@ -164,6 +165,8 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: a trace of OmegaConf containers _partial_: If True, return functools.partial wrapped method or object False by default. Configure per target. + _resolve_: If to resolve the OmegaConf configuration (bool) + True by default. :param args: Optional positional parameters pass-through :param kwargs: Optional named parameters to override parameters in the config object. Parameters not present @@ -212,8 +215,11 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: if kwargs: config = OmegaConf.merge(config, kwargs) - - OmegaConf.resolve(config) + + _resolve_ = config.pop(_Keys.RESOLVE, True) + + if _resolve_: + OmegaConf.resolve(config) _recursive_ = config.pop(_Keys.RECURSIVE, True) _convert_ = config.pop(_Keys.CONVERT, ConvertMode.NONE) @@ -231,7 +237,10 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: config_copy._set_parent(config._get_parent()) config = config_copy - OmegaConf.resolve(config) + _resolve_ = config.pop(_Keys.RESOLVE, True) + + if _resolve_: + OmegaConf.resolve(config) _recursive_ = kwargs.pop(_Keys.RECURSIVE, True) _convert_ = kwargs.pop(_Keys.CONVERT, ConvertMode.NONE) From 25a7dedd76d91f8ce60065955ba0c626134ed099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:41:55 +0200 Subject: [PATCH 02/13] Add instantiation test with _resolve_=False flag. --- tests/instantiate/test_instantiate.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/instantiate/test_instantiate.py b/tests/instantiate/test_instantiate.py index 6f3c8111872..7572fec2974 100644 --- a/tests/instantiate/test_instantiate.py +++ b/tests/instantiate/test_instantiate.py @@ -103,6 +103,19 @@ def config(request: Any, src: Any) -> Any: AClass(10, 20, 30, 40), id="class", ), + param( + { + "_target_": "tests.instantiate.AClass", + "a": "${somethingthatisjustpassed}", + "b": 20, + "c": 30, + "d": 40, + "_resolve_": False + }, + {}, + AClass("somethingthatisjustpassed", 20, 30, 40), + id="class+not_resolve", + ), param( { "_target_": "tests.instantiate.AClass", From af6a0f0cda3365d7789d8f507cd7425006f34d53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 12:47:17 +0200 Subject: [PATCH 03/13] Update the documentation of instantiate. Update the documentation of instantiate for optionally disabling the OmegaConf resolution. --- website/docs/advanced/instantiate_objects/overview.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/website/docs/advanced/instantiate_objects/overview.md b/website/docs/advanced/instantiate_objects/overview.md index a23c2b4b6da..f789532eeb8 100644 --- a/website/docs/advanced/instantiate_objects/overview.md +++ b/website/docs/advanced/instantiate_objects/overview.md @@ -40,6 +40,8 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: a trace of OmegaConf containers _partial_: If True, return functools.partial wrapped method or object False by default. Configure per target. + _resolve_: If to resolve the OmegaConf configuration (bool) + True by default. :param args: Optional positional parameters pass-through :param kwargs: Optional named parameters to override parameters in the config object. Parameters not present @@ -369,6 +371,9 @@ assert bar1.foo is bar2.foo # the `Foo` instance is re-used here This does not apply if `_partial_=False`, in which case a new `Foo` instance would be created with each call to `instantiate`. +### OmegaConf resolution +By default, the configuration is resolved via `OmegaConf.resolve`. This can be turned off, using `_resolve_=False`. + ### Instantiation of builtins From 9ffd08082dbe4e0ea146590223fc4e3ceaacd631 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 14:11:55 +0200 Subject: [PATCH 04/13] Debug ListConfig instantiation, no _resolve_ flag. --- hydra/_internal/instantiate/_instantiate2.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index fcade18f863..759ebf1c102 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -237,10 +237,7 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: config_copy._set_parent(config._get_parent()) config = config_copy - _resolve_ = config.pop(_Keys.RESOLVE, True) - - if _resolve_: - OmegaConf.resolve(config) + OmegaConf.resolve(config) _recursive_ = kwargs.pop(_Keys.RECURSIVE, True) _convert_ = kwargs.pop(_Keys.CONVERT, ConvertMode.NONE) From 9bbebca16935c4cb71dec4b67ab2121ce4d030f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 14:50:48 +0200 Subject: [PATCH 05/13] Make resolve configurable in _convert_node. --- hydra/_internal/instantiate/_instantiate2.py | 37 +++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 759ebf1c102..89610976e69 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -262,13 +262,17 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: ) -def _convert_node(node: Any, convert: Union[ConvertMode, str]) -> Any: +def _convert_node( + node: Any, + convert: Union[ConvertMode, str], + resolve: bool = True +) -> Any: if OmegaConf.is_config(node): if convert == ConvertMode.ALL: - node = OmegaConf.to_container(node, resolve=True) + node = OmegaConf.to_container(node, resolve=resolve) elif convert == ConvertMode.PARTIAL: node = OmegaConf.to_container( - node, resolve=True, structured_config_mode=SCMode.DICT_CONFIG + node, resolve=resolve, structured_config_mode=SCMode.DICT_CONFIG ) return node @@ -279,6 +283,7 @@ def instantiate_node( convert: Union[str, ConvertMode] = ConvertMode.NONE, recursive: bool = True, partial: bool = False, + resolve: bool = True, ) -> Any: # Return None if config is None if node is None or (OmegaConf.is_config(node) and node._is_none()): @@ -294,6 +299,7 @@ def instantiate_node( convert = node[_Keys.CONVERT] if _Keys.CONVERT in node else convert recursive = node[_Keys.RECURSIVE] if _Keys.RECURSIVE in node else recursive partial = node[_Keys.PARTIAL] if _Keys.PARTIAL in node else partial + convert = node[_Keys.RESOLVE] if _Keys.CONVERT in node else resolve full_key = node._get_full_key(None) @@ -302,6 +308,12 @@ def instantiate_node( if full_key: msg += f"\nfull_key: {full_key}" raise TypeError(msg) + + if not isinstance(resolve, bool): + msg = f"Instantiation: _resolve_ flag must be a bool, got {type(recursive)}" + if full_key: + msg += f"\nfull_key: {full_key}" + raise TypeError(msg) if not isinstance(partial, bool): msg = f"Instantiation: _partial_ flag must be a bool, got {type( partial )}" @@ -312,7 +324,11 @@ def instantiate_node( # If OmegaConf list, create new list of instances if recursive if OmegaConf.is_list(node): items = [ - instantiate_node(item, convert=convert, recursive=recursive) + instantiate_node( + item, + convert=convert, + recursive=recursive, + resolve=resolve) for item in node._iter_ex(resolve=True) ] @@ -326,11 +342,13 @@ def instantiate_node( return lst elif OmegaConf.is_dict(node): - exclude_keys = set({"_target_", "_convert_", "_recursive_", "_partial_"}) + exclude_keys = set({ + "_target_", "_convert_", "_recursive_", "_partial_", "_resolve_"}) if _is_target(node): _target_ = _resolve_target(node.get(_Keys.TARGET), full_key) kwargs = {} is_partial = node.get("_partial_", False) or partial + is_resolve = node.get("_resolve_", True) or resolve for key in node.keys(): if key not in exclude_keys: if OmegaConf.is_missing(node, key) and is_partial: @@ -338,9 +356,10 @@ def instantiate_node( value = node[key] if recursive: value = instantiate_node( - value, convert=convert, recursive=recursive + value, convert=convert, recursive=recursive, + resolve=is_resolve, ) - kwargs[key] = _convert_node(value, convert) + kwargs[key] = _convert_node(value, convert, resolve=is_resolve) return _call_target(_target_, partial, args, kwargs, full_key) else: @@ -353,7 +372,7 @@ def instantiate_node( for key, value in node.items(): # list items inherits recursive flag from the containing dict. dict_items[key] = instantiate_node( - value, convert=convert, recursive=recursive + value, convert=convert, recursive=recursive, resolve=resolve, ) return dict_items else: @@ -361,7 +380,7 @@ def instantiate_node( cfg = OmegaConf.create({}, flags={"allow_objects": True}) for key, value in node.items(): cfg[key] = instantiate_node( - value, convert=convert, recursive=recursive + value, convert=convert, recursive=recursive, resolve=resolve, ) cfg._set_parent(node) cfg._metadata.object_type = node._metadata.object_type From cfb0526dc14335a00fa64d7a306b35d47c458ad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 15:25:09 +0200 Subject: [PATCH 06/13] Debug linter errors because of wrong spaces. --- hydra/_internal/instantiate/_instantiate2.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 89610976e69..77adbd1e00b 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -165,7 +165,7 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: a trace of OmegaConf containers _partial_: If True, return functools.partial wrapped method or object False by default. Configure per target. - _resolve_: If to resolve the OmegaConf configuration (bool) + _resolve_: If to resolve the OmegaConf configuration (bool) True by default. :param args: Optional positional parameters pass-through :param kwargs: Optional named parameters to override @@ -215,9 +215,9 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: if kwargs: config = OmegaConf.merge(config, kwargs) - + _resolve_ = config.pop(_Keys.RESOLVE, True) - + if _resolve_: OmegaConf.resolve(config) @@ -308,7 +308,7 @@ def instantiate_node( if full_key: msg += f"\nfull_key: {full_key}" raise TypeError(msg) - + if not isinstance(resolve, bool): msg = f"Instantiation: _resolve_ flag must be a bool, got {type(recursive)}" if full_key: From d01597fee1666506baba68416375573697c36aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 15:29:34 +0200 Subject: [PATCH 07/13] Debug resolution logic. --- hydra/_internal/instantiate/_instantiate2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 77adbd1e00b..8c60de87ab0 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -348,7 +348,7 @@ def instantiate_node( _target_ = _resolve_target(node.get(_Keys.TARGET), full_key) kwargs = {} is_partial = node.get("_partial_", False) or partial - is_resolve = node.get("_resolve_", True) or resolve + is_resolve = node.get("_resolve_", True) and resolve for key in node.keys(): if key not in exclude_keys: if OmegaConf.is_missing(node, key) and is_partial: From ec45a8143554461f5abbb7a51f7906c145f3c332 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 15:32:08 +0200 Subject: [PATCH 08/13] Debug resolution logic. --- hydra/_internal/instantiate/_instantiate2.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 8c60de87ab0..7272c05ec37 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -348,7 +348,9 @@ def instantiate_node( _target_ = _resolve_target(node.get(_Keys.TARGET), full_key) kwargs = {} is_partial = node.get("_partial_", False) or partial - is_resolve = node.get("_resolve_", True) and resolve + is_resolve = ( + (node.get("_resolve_", None) is None and resolve) + or node.get("_resolve_", True)) for key in node.keys(): if key not in exclude_keys: if OmegaConf.is_missing(node, key) and is_partial: From eb0ceef74b5d3620c8f6799da517a3d599e68b8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 16:09:03 +0200 Subject: [PATCH 09/13] Debug resolution. --- hydra/_internal/instantiate/_instantiate2.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 7272c05ec37..354629e3b43 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -226,7 +226,8 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: _partial_ = config.pop(_Keys.PARTIAL, False) return instantiate_node( - config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_ + config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_, + resolve=_resolve, ) elif OmegaConf.is_list(config): # Finalize config (convert targets to strings, merge with kwargs) @@ -249,7 +250,8 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: ) return instantiate_node( - config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_ + config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_, + resolve=_resolve, ) else: raise InstantiationException( @@ -265,7 +267,7 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: def _convert_node( node: Any, convert: Union[ConvertMode, str], - resolve: bool = True + resolve: bool = True, ) -> Any: if OmegaConf.is_config(node): if convert == ConvertMode.ALL: @@ -329,7 +331,7 @@ def instantiate_node( convert=convert, recursive=recursive, resolve=resolve) - for item in node._iter_ex(resolve=True) + for item in node._iter_ex(resolve=resolve) ] if convert in (ConvertMode.ALL, ConvertMode.PARTIAL): From 1289c3125d5cd30e109076da2b92b875fcc70284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 16:10:49 +0200 Subject: [PATCH 10/13] Debug resolution. --- hydra/_internal/instantiate/_instantiate2.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 354629e3b43..0527ad3ee8a 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -227,7 +227,7 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: return instantiate_node( config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_, - resolve=_resolve, + resolve=_resolve_, ) elif OmegaConf.is_list(config): # Finalize config (convert targets to strings, merge with kwargs) @@ -251,7 +251,7 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: return instantiate_node( config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_, - resolve=_resolve, + resolve=_resolve_, ) else: raise InstantiationException( From c57ee3f8f04de1da587194e21c748fba4662f7d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korbinian=20P=C3=B6ppel?= <37810656+kpoeppel@users.noreply.github.com> Date: Mon, 20 Jun 2022 16:45:07 +0200 Subject: [PATCH 11/13] Debug uninitialized variable. --- hydra/_internal/instantiate/_instantiate2.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 0527ad3ee8a..f129f10bab2 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -243,6 +243,7 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: _recursive_ = kwargs.pop(_Keys.RECURSIVE, True) _convert_ = kwargs.pop(_Keys.CONVERT, ConvertMode.NONE) _partial_ = kwargs.pop(_Keys.PARTIAL, False) + _resolve_ = True if _partial_: raise InstantiationException( From e586dc7a23acfbb438e2f924479ccc681e20b8fe Mon Sep 17 00:00:00 2001 From: Korbinian Poeppel Date: Thu, 28 Jul 2022 09:26:32 +0200 Subject: [PATCH 12/13] Debug bad resolution logic. --- hydra/_internal/instantiate/_instantiate2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index f129f10bab2..e3be2f0a343 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -353,7 +353,7 @@ def instantiate_node( is_partial = node.get("_partial_", False) or partial is_resolve = ( (node.get("_resolve_", None) is None and resolve) - or node.get("_resolve_", True)) + or node.get("_resolve_", False)) for key in node.keys(): if key not in exclude_keys: if OmegaConf.is_missing(node, key) and is_partial: From d2582f3ae7db3722027e1a31dec2a4f1775c1594 Mon Sep 17 00:00:00 2001 From: Jasha <8935917+Jasha10@users.noreply.github.com> Date: Sun, 6 Nov 2022 05:54:06 -0600 Subject: [PATCH 13/13] black formatting --- hydra/_internal/instantiate/_instantiate2.py | 43 +++++++++++++------- tests/instantiate/test_instantiate.py | 2 +- 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/hydra/_internal/instantiate/_instantiate2.py b/hydra/_internal/instantiate/_instantiate2.py index 0d1d815d585..70b1a295f91 100644 --- a/hydra/_internal/instantiate/_instantiate2.py +++ b/hydra/_internal/instantiate/_instantiate2.py @@ -226,7 +226,11 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: _partial_ = config.pop(_Keys.PARTIAL, False) return instantiate_node( - config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_, + config, + *args, + recursive=_recursive_, + convert=_convert_, + partial=_partial_, resolve=_resolve_, ) elif OmegaConf.is_list(config): @@ -251,7 +255,11 @@ def instantiate(config: Any, *args: Any, **kwargs: Any) -> Any: ) return instantiate_node( - config, *args, recursive=_recursive_, convert=_convert_, partial=_partial_, + config, + *args, + recursive=_recursive_, + convert=_convert_, + partial=_partial_, resolve=_resolve_, ) else: @@ -328,10 +336,8 @@ def instantiate_node( if OmegaConf.is_list(node): items = [ instantiate_node( - item, - convert=convert, - recursive=recursive, - resolve=resolve) + item, convert=convert, recursive=recursive, resolve=resolve + ) for item in node._iter_ex(resolve=resolve) ] @@ -345,15 +351,16 @@ def instantiate_node( return lst elif OmegaConf.is_dict(node): - exclude_keys = set({ - "_target_", "_convert_", "_recursive_", "_partial_", "_resolve_"}) + exclude_keys = set( + {"_target_", "_convert_", "_recursive_", "_partial_", "_resolve_"} + ) if _is_target(node): _target_ = _resolve_target(node.get(_Keys.TARGET), full_key) kwargs = {} is_partial = node.get("_partial_", False) or partial - is_resolve = ( - (node.get("_resolve_", None) is None and resolve) - or node.get("_resolve_", False)) + is_resolve = (node.get("_resolve_", None) is None and resolve) or node.get( + "_resolve_", False + ) for key in node.keys(): if key not in exclude_keys: if OmegaConf.is_missing(node, key) and is_partial: @@ -361,7 +368,9 @@ def instantiate_node( value = node[key] if recursive: value = instantiate_node( - value, convert=convert, recursive=recursive, + value, + convert=convert, + recursive=recursive, resolve=is_resolve, ) kwargs[key] = _convert_node(value, convert, resolve=is_resolve) @@ -377,7 +386,10 @@ def instantiate_node( for key, value in node.items(): # list items inherits recursive flag from the containing dict. dict_items[key] = instantiate_node( - value, convert=convert, recursive=recursive, resolve=resolve, + value, + convert=convert, + recursive=recursive, + resolve=resolve, ) return dict_items else: @@ -385,7 +397,10 @@ def instantiate_node( cfg = OmegaConf.create({}, flags={"allow_objects": True}) for key, value in node.items(): cfg[key] = instantiate_node( - value, convert=convert, recursive=recursive, resolve=resolve, + value, + convert=convert, + recursive=recursive, + resolve=resolve, ) cfg._set_parent(node) cfg._metadata.object_type = node._metadata.object_type diff --git a/tests/instantiate/test_instantiate.py b/tests/instantiate/test_instantiate.py index 898e44ac4d3..238f25bead4 100644 --- a/tests/instantiate/test_instantiate.py +++ b/tests/instantiate/test_instantiate.py @@ -110,7 +110,7 @@ def config(request: Any, src: Any) -> Any: "b": 20, "c": 30, "d": 40, - "_resolve_": False + "_resolve_": False, }, {}, AClass("somethingthatisjustpassed", 20, 30, 40),