diff --git a/omegaconf/omegaconf.py b/omegaconf/omegaconf.py index c8c3797b5..d291f36b6 100644 --- a/omegaconf/omegaconf.py +++ b/omegaconf/omegaconf.py @@ -746,7 +746,13 @@ def update( assert False @staticmethod - def to_yaml(cfg: Any, *, resolve: bool = False, sort_keys: bool = False) -> str: + def to_yaml( + cfg: Any, + *, + resolve: bool = False, + sort_keys: bool = False, + default_flow_style: Optional[bool] = False + ) -> str: """ returns a yaml dump of this config object. @@ -754,13 +760,19 @@ def to_yaml(cfg: Any, *, resolve: bool = False, sort_keys: bool = False) -> str: :param resolve: if True, will return a string with the interpolations resolved, otherwise interpolations are preserved :param sort_keys: If True, will print dict keys in sorted order. default False. + :param default_flow_style: Set default_flow_style option for PyYAML's yaml.dump(). + Choices: + - False: Always use block style for collections + - True: Always use flow style + - None: Use block style for nested collections, otherwise use flow style + default False. :return: A string containing the yaml representation. """ cfg = _ensure_container(cfg) container = OmegaConf.to_container(cfg, resolve=resolve, enum_to_str=True) return yaml.dump( # type: ignore container, - default_flow_style=False, + default_flow_style=default_flow_style, allow_unicode=True, sort_keys=sort_keys, Dumper=get_omega_conf_dumper(),