From d888120ea7a5b3459b3a2737ec0cca2a3d033158 Mon Sep 17 00:00:00 2001 From: Wouter Zwerink <35296208+wouterzwerink@users.noreply.github.com> Date: Wed, 17 Jan 2024 16:51:29 +0100 Subject: [PATCH] Use CDumper whenever possible (#1152) Use CDumper whenever possible0 --- news/1152.feature | 1 + omegaconf/_utils.py | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 news/1152.feature diff --git a/news/1152.feature b/news/1152.feature new file mode 100644 index 000000000..72aaff48c --- /dev/null +++ b/news/1152.feature @@ -0,0 +1 @@ +The YAML dumper will now use `yaml.CDumper` instead of `yaml.Dumper` whenever possible to speed up dumping diff --git a/omegaconf/_utils.py b/omegaconf/_utils.py index ec07aa51f..2575f0452 100644 --- a/omegaconf/_utils.py +++ b/omegaconf/_utils.py @@ -41,6 +41,13 @@ except ImportError: # pragma: no cover BaseLoader = yaml.SafeLoader +try: + from yaml import CDumper + + BaseDumper = CDumper +except ImportError: # pragma: no cover + BaseDumper = yaml.Dumper + NoneType: Type[None] = type(None) BUILTIN_VALUE_TYPES: Tuple[Type[Any], ...] = ( @@ -105,7 +112,7 @@ def __repr__(self) -> str: _DEFAULT_MARKER_: Any = Marker("_DEFAULT_MARKER_") -class OmegaConfDumper(yaml.Dumper): # type: ignore +class OmegaConfDumper(BaseDumper): # type: ignore str_representer_added = False @staticmethod