Update omegaconf_no_object_check

This commit is contained in:
lematt1991 2023-09-25 19:12:47 +00:00
parent fdca11448e
commit 01476cfeaf

View File

@ -364,14 +364,24 @@ def override_module_args(args: Namespace) -> Tuple[List[str], List[str]]:
class omegaconf_no_object_check:
def __init__(self):
self.old_is_primitive = _utils.is_primitive_type
# Changed in https://github.com/omry/omegaconf/pull/911 - both are kept for back compat.
if hasattr(_utils, "is_primitive_type"):
self.old_is_primitive = _utils.is_primitive_type
else:
self.old_is_primitive = _utils.is_primitive_type_annotation
def __enter__(self):
_utils.is_primitive_type = lambda _: True
if hasattr(_utils, "is_primitive_type"):
_utils.is_primitive_type = lambda _: True
else:
_utils.is_primitive_type_annotation = lambda _: True
def __exit__(self, type, value, traceback):
_utils.is_primitive_type = self.old_is_primitive
if hasattr(_utils, "is_primitive_type"):
_utils.is_primitive_type = self.old_is_primitive
else:
_utils.is_primitive_type_annotation = self.old_is_primitive
def convert_namespace_to_omegaconf(args: Namespace) -> DictConfig:
"""Convert a flat argparse.Namespace to a structured DictConfig."""