Skip to content

Commit

Permalink
Use CSafeLoader when possible (omry#1150)
Browse files Browse the repository at this point in the history
Use CSafeLoader when possible

---------

Co-authored-by: Olivier Delalleau <[email protected]>
  • Loading branch information
wouterzwerink and odelalleau authored Jan 16, 2024
1 parent fd73050 commit b5badbd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/1150.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The YAML parser will now use `yaml.CSafeLoader` instead of `yaml.SafeLoader` whenever possible to speed up parsing
9 changes: 8 additions & 1 deletion omegaconf/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@
except ImportError: # pragma: no cover
attr = None # type: ignore # pragma: no cover

try:
from yaml import CSafeLoader

BaseLoader = CSafeLoader
except ImportError: # pragma: no cover
BaseLoader = yaml.SafeLoader

NoneType: Type[None] = type(None)

BUILTIN_VALUE_TYPES: Tuple[Type[Any], ...] = (
Expand Down Expand Up @@ -123,7 +130,7 @@ def yaml_is_bool(b: str) -> bool:


def get_yaml_loader() -> Any:
class OmegaConfLoader(yaml.SafeLoader): # type: ignore
class OmegaConfLoader(BaseLoader): # type: ignore
def construct_mapping(self, node: yaml.Node, deep: bool = False) -> Any:
keys = set()
for key_node, value_node in node.value:
Expand Down

0 comments on commit b5badbd

Please sign in to comment.