Skip to main content

specfile.formatter

format_expression

def format_expression(expression: str, line_length_threshold: int = 80) -> str

Formats the specified Python expression.

Only supports a small subset of Python AST that should be sufficient for use in __repr__().

Arguments:

  • expression - Python expression to reformat.
  • line_length_threshold - Threshold for line lengths. It's not a hard limit, it can be exceeded in some cases.

Returns:

Formatted expression.

Raises:

  • SyntaxError - If the expression is not parseable.
  • SpecfileException - If there is an unsupported AST node in the expression.

formatted

def formatted(function: Callable[..., str]) -> Callable[..., str]

Decorator for formatting the output of __repr__().