|
9 | 9 | from importlib import import_module |
10 | 10 | from pathlib import Path |
11 | 11 | from types import ModuleType |
12 | | -from typing import Any, Callable, Dict, Optional, Set, overload |
| 12 | +from typing import Any, Callable, Dict, Optional, Set, Union, overload |
13 | 13 |
|
14 | 14 | from ._common import Action, null_logger |
15 | 15 | from ._common import LoggerProperty as InternalLoggerProperty |
|
28 | 28 | "ParserError", |
29 | 29 | "compose_dataclasses", |
30 | 30 | "get_config_read_mode", |
| 31 | + "dict_to_namespace", |
31 | 32 | "namespace_to_dict", |
32 | 33 | "null_logger", |
33 | 34 | "set_docstring_parse_options", |
@@ -123,8 +124,6 @@ def patched_init(self, *args, parse_as_dict: bool = False, **kwargs): |
123 | 124 | ArgumentParser._unpatched_init = ArgumentParser.__init__ |
124 | 125 | ArgumentParser.__init__ = patched_init |
125 | 126 |
|
126 | | - from typing import Union |
127 | | - |
128 | 127 | # Patch parse methods |
129 | 128 | def patch_parse_method(method_name): |
130 | 129 | unpatched_method_name = "_unpatched_" + method_name |
@@ -707,6 +706,21 @@ def namespace_to_dict(namespace: Namespace) -> Dict[str, Any]: |
707 | 706 | return namespace.clone().as_dict() |
708 | 707 |
|
709 | 708 |
|
| 709 | +@deprecated( |
| 710 | + """ |
| 711 | + dict_to_namespace was deprecated in v4.43.0 and will be removed in v5.0.0. |
| 712 | + No replacement is provided because blindly converting a dictionary to a |
| 713 | + namespace may not yield the same results as using a parser, which could lead |
| 714 | + to confusion. |
| 715 | +""" |
| 716 | +) |
| 717 | +def dict_to_namespace(cfg_dict: dict[str, Any]) -> Namespace: |
| 718 | + """Converts a nested dictionary into a nested namespace.""" |
| 719 | + from ._namespace import dict_to_namespace as _dict_to_namespace |
| 720 | + |
| 721 | + return _dict_to_namespace(cfg_dict) |
| 722 | + |
| 723 | + |
710 | 724 | @overload |
711 | 725 | def strip_meta(cfg: "Namespace") -> "Namespace": ... # pragma: no cover |
712 | 726 |
|
|
0 commit comments