torchoutil.extras.yaml module

class IgnoreTagLoader(
stream,
)[source]

Bases: SafeLoader

SafeLoader that ignores yaml tags.

```python >>> dumped = “a: !!python/tuple

  • 1

  • 2”
    >>> yaml.load(dumped, Loader=IgnoreTagLoader)
    ... {"a": [1, 2]}
    >>> yaml.load(dumped, Loader=FullLoader)
    ... {"a": (1, 2)}
    >>> yaml.load(dumped, Loader=SafeLoader)  # raises ConstructorError
    ```
    
construct_with_tag(
tag: str,
node: Node,
) Any[source]
yaml_multi_constructors = {'!': <function IgnoreTagLoader.construct_with_tag>, 'tag:': <function IgnoreTagLoader.construct_with_tag>}
dump_yaml(
data: Iterable[Any] | Mapping[str, Any] | Namespace | DataclassInstance | NamedTupleInstance,
fpath: str | Path | None = None,
*,
overwrite: bool = True,
to_builtins: bool = False,
make_parents: bool = True,
resolve: bool = False,
encoding: str | None = 'utf-8',
sort_keys: bool = False,
indent: int | None = None,
width: int | None = 1000,
allow_unicode: bool = True,
**yaml_dump_kwds,
) str[source]

Dump content to yaml format.

load_yaml(
fpath: str | ~pathlib.Path | ~_io.TextIOWrapper,
*,
Loader: ~typing.Type[~yaml.loader.Loader] | ~typing.Type[~yaml.loader.BaseLoader] | ~typing.Type[~yaml.loader.FullLoader] | ~typing.Type[~yaml.loader.SafeLoader] | ~typing.Type[~yaml.loader.UnsafeLoader] | ~typing.Type[~yaml.cyaml.CLoader] | ~typing.Type[~yaml.cyaml.CBaseLoader] | ~typing.Type[~yaml.cyaml.CFullLoader] | ~typing.Type[~yaml.cyaml.CSafeLoader] | ~typing.Type[~yaml.cyaml.CUnsafeLoader] = <class 'yaml.loader.SafeLoader'>,
on_error: ~typing.Literal['raise',
'ignore'] = 'raise',
) Any[source]

Load content from yaml filepath.

to_yaml(
data: Iterable[Any] | Mapping[str, Any] | Namespace | DataclassInstance | NamedTupleInstance,
fpath: str | Path | None = None,
*,
overwrite: bool = True,
to_builtins: bool = False,
make_parents: bool = True,
resolve: bool = False,
encoding: str | None = 'utf-8',
sort_keys: bool = False,
indent: int | None = None,
width: int | None = 1000,
allow_unicode: bool = True,
**yaml_dump_kwds,
) str[source]

Dump content to yaml format.