g_docformatter.formatters.text

Callable classes that are specialized for formatting text blocks at the final formatting of a docstring paragraph.

class g_docformatter.formatters.text.TextFormatterABC(settings: FormatterSettings)

Bases: ABC

Abstract base class for text formatters.

abstractmethod format_text(text: str, indent_level: int) str

Format a block of text with appropriate indentation.

This abstract method must be implemented by subclasses to define their specific text formatting behavior. The superclass implementation returns the text as-is.

Parameters:
  • text – The text block to format.

  • indent_level – The indentation level (0-based) to apply to the formatted text.

Returns:

The formatted text string with correct indentation applied.

class g_docformatter.formatters.text.AsIsTextFormatter(settings: FormatterSettings)

Bases: TextFormatterABC

A text formatter that returns the text as-is without any formatting.

format_text(text: str, indent_level: int) str

Format a block of text with appropriate indentation.

This abstract method must be implemented by subclasses to define their specific text formatting behavior. The superclass implementation returns the text as-is.

Parameters:
  • text – The text block to format.

  • indent_level – The indentation level (0-based) to apply to the formatted text.

Returns:

The formatted text string with correct indentation applied.

class g_docformatter.formatters.text.InverseHangingIndentTextFormatter(settings: FormatterSettings)

Bases: TextFormatterABC

A text formatter that applies the opposite of hanging indentation, where the first line is not indented and subsequent lines are indented at the indent_level.

format_text(text: str, indent_level: int) str

Format a block of text with appropriate indentation.

This abstract method must be implemented by subclasses to define their specific text formatting behavior. The superclass implementation returns the text as-is.

Parameters:
  • text – The text block to format.

  • indent_level – The indentation level (0-based) to apply to the formatted text.

Returns:

The formatted text string with correct indentation applied.

class g_docformatter.formatters.text.IndentOnlyTextFormatter(settings: FormatterSettings)

Bases: TextFormatterABC

A text formatter that indents each line of text according to the specified indentation level, but does not apply any wrapping.

format_text(text: str, indent_level: int) str

Format a block of text with appropriate indentation.

This abstract method must be implemented by subclasses to define their specific text formatting behavior. The superclass implementation returns the text as-is.

Parameters:
  • text – The text block to format.

  • indent_level – The indentation level (0-based) to apply to the formatted text.

Returns:

The formatted text string with correct indentation applied.

class g_docformatter.formatters.text.UniformIndentTextFormatter(settings: FormatterSettings)

Bases: TextFormatterABC

A simple text formatter that uses textwrap.fill.

format_text(text: str, indent_level: int) str

Format a block of text with appropriate indentation.

This abstract method must be implemented by subclasses to define their specific text formatting behavior. The superclass implementation returns the text as-is.

Parameters:
  • text – The text block to format.

  • indent_level – The indentation level (0-based) to apply to the formatted text.

Returns:

The formatted text string with correct indentation applied.

class g_docformatter.formatters.text.HangingIndentTextFormatter(settings: FormatterSettings)

Bases: TextFormatterABC

A text formatter that applies hanging indentation, where the first line is indented at the indent_level and subsequent lines are indented one level further.

format_text(text: str, indent_level: int) str

Format a block of text with appropriate indentation.

This abstract method must be implemented by subclasses to define their specific text formatting behavior. The superclass implementation returns the text as-is.

Parameters:
  • text – The text block to format.

  • indent_level – The indentation level (0-based) to apply to the formatted text.

Returns:

The formatted text string with correct indentation applied.

class g_docformatter.formatters.text.BlackTextFormatter(settings: FormatterSettings, formatter_options: dict[str, Any] | None = None)

Bases: TextFormatterABC

A text formatter that uses the Black code formatter for formatting.

The formatter first dedents the input text to remove any existing indentation before passing it to Black. After Black returns the formatted string the result is indented to the requested level and trailing whitespace or newline characters are stripped with rstrip().

format_text(text: str, indent_level: int) str

Format a block of text with appropriate indentation.

This abstract method must be implemented by subclasses to define their specific text formatting behavior. The superclass implementation returns the text as-is.

Parameters:
  • text – The text block to format.

  • indent_level – The indentation level (0-based) to apply to the formatted text.

Returns:

The formatted text string with correct indentation applied.