Returns a debug string for the config. Args: kv_separator: The key-value separator. field_separator: The field separator. omit_default_values: A set of default values to omit in debug string. See comments on `to_flat_dict`. Return
(
self,
*,
kv_separator: str = ": ",
field_separator: str = "\n",
omit_default_values: Collection[Any] = (None, REQUIRED),
)
| 586 | return attr.evolve(self).set(**kwargs) |
| 587 | |
| 588 | def debug_string( |
| 589 | self, |
| 590 | *, |
| 591 | kv_separator: str = ": ", |
| 592 | field_separator: str = "\n", |
| 593 | omit_default_values: Collection[Any] = (None, REQUIRED), |
| 594 | ) -> str: |
| 595 | """Returns a debug string for the config. |
| 596 | |
| 597 | Args: |
| 598 | kv_separator: The key-value separator. |
| 599 | field_separator: The field separator. |
| 600 | omit_default_values: A set of default values to omit in debug string. |
| 601 | See comments on `to_flat_dict`. |
| 602 | |
| 603 | Returns: |
| 604 | A str separated by `field_separator` where each entry is of form |
| 605 | f"{path}{kv_separator}{val}", representing path and value of a leaf config field. |
| 606 | """ |
| 607 | flat_dict = self.to_flat_dict(omit_default_values=omit_default_values) |
| 608 | |
| 609 | def fmt(key: str, val: Any) -> Union[str, tuple[str, str]]: |
| 610 | if isinstance(val, (type, types.FunctionType)): |
| 611 | val = f"{val.__module__}.{val.__name__}" |
| 612 | return f"{key}{kv_separator}{repr(val)}" |
| 613 | |
| 614 | return field_separator.join([fmt(k, v) for k, v in flat_dict.items()]) |
| 615 | |
| 616 | def to_flat_dict(self, *, omit_default_values: Collection[Any]) -> dict[str, Any]: |
| 617 | """Returns a flattened dict with path -> value mappings. |