Skip to content

Commit

Permalink
Improve docstring of new str utility
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianSosic authored and AVHopp committed Sep 5, 2024
1 parent a6a943e commit ae63fdf
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions baybe/utils/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,17 @@ def format(header: str, fields: list[Any], *, single_line: bool = False) -> str:
"""Create a nested string representation.
Args:
header: The header, typically the name of the class.
fields: List of fields that should be printed with an indentation.
single_line: If ``True``, print the representation on a single line. Used for
simple fields that would require manual configuration otherwise. Only
applicable for lists with a single fields.
header: The header, typically the name of a class.
fields: Fields to be printed with an indentation.
single_line: If ``True``, print the representation on a single line.
Only applicable when given a single field.
Raises:
ValueError: If ``single_line`` is ``True`` but ``fields`` contains more than one
element.
Returns:
The representation with indented fields.
The string representation with indented fields.
"""
# Add a ":" to header if it does not end with a ":"
if not header.endswith(":"):
Expand All @@ -172,7 +171,7 @@ def format(header: str, fields: list[Any], *, single_line: bool = False) -> str:
if single_line:
if len(fields) > 1:
raise ValueError(
"single_line is only applicable for lists with a single field"
"``single_line`` is only applicable when given a single field."
)
return f"{header} {str(fields[0])}"

Expand Down

0 comments on commit ae63fdf

Please sign in to comment.