Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CSafeLoader when possible #1150

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1150.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Yaml parser will now use `yaml.CSafeLoader` instead of `yaml.SafeLoader` whenever possible to speed up parsing.
wouterzwerink marked this conversation as resolved.
Show resolved Hide resolved
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