torchwrench.extras.yaml.yaml module

class torchwrench.extras.yaml.yaml.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>}
class torchwrench.extras.yaml.yaml.SplitTagLoader(stream, *, tag_key: str = '_target_', args_key: str = '_args_')[source]

Bases: SafeLoader

SafeLoader that store tags inside value.

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

  • 1

  • 2”
    >>> yaml.load(dumped, Loader=SplitTagLoader)
    ... {'a': {'_target_': 'yaml.org,2002:python/tuple', '_args_': [1, 2]}}
    ```
    
construct_with_tag(tag: str, node: Node) Any[source]
yaml_multi_constructors = {'!': <function SplitTagLoader.construct_with_tag>, 'tag:': <function SplitTagLoader.construct_with_tag>}
torchwrench.extras.yaml.yaml.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.

torchwrench.extras.yaml.yaml.dumps_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.

torchwrench.extras.yaml.yaml.load_yaml(file: str | Path | TextIOBase, *, Loader: type[Loader] | type[BaseLoader] | type[FullLoader] | type[SafeLoader] | type[UnsafeLoader] | type[CLoader] | type[CBaseLoader] | type[CFullLoader] | type[CSafeLoader] | type[CUnsafeLoader] = <class 'yaml.loader.SafeLoader'>, on_error: Literal['raise', 'ignore']='raise') Any[source]

Load YAML from filepath or opened file.

torchwrench.extras.yaml.yaml.loads_yaml(content: str | TextIOBase, *, Loader: type[Loader] | type[BaseLoader] | type[FullLoader] | type[SafeLoader] | type[UnsafeLoader] | type[CLoader] | type[CBaseLoader] | type[CFullLoader] | type[CSafeLoader] | type[CUnsafeLoader] = <class 'yaml.loader.SafeLoader'>, on_error: Literal['raise', 'ignore']='raise') Any[source]

Load YAML from string and text-io stream.

torchwrench.extras.yaml.yaml.read_yaml(file: str | Path | TextIOBase, *, Loader: type[Loader] | type[BaseLoader] | type[FullLoader] | type[SafeLoader] | type[UnsafeLoader] | type[CLoader] | type[CBaseLoader] | type[CFullLoader] | type[CSafeLoader] | type[CUnsafeLoader] = <class 'yaml.loader.SafeLoader'>, on_error: Literal['raise', 'ignore']='raise') Any[source]

Load YAML from filepath or opened file.

torchwrench.extras.yaml.yaml.save_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.