Skip to content

Add help string formatters that don't use escaped characters. #2882

Description

@Phrogz

I'd love to use the \f and \b in my docstrings to have a single source of help text. However, Ruff D301 enforces PEP 257 which requires docstrings to be raw (r"""…""") if they have any backslashes in them. Doing that breaks the VS Code syntax highlighting to no longer treat the string as a docstring.

So, I've had to move documentation out of the docstring for the function and into the help argument, repeating the docstring first line, all because I want to use \b and \f to fight Click's helpful auto-formatting. Please add an additional formatting mechanism to support these functions. If I'm going to put visual garbage in my source file to get the formatting to behave, it would be nice if it were self-documenting, e.g.

@click.option(…)
@click.option(…)
def myfunc(cats: int = 0, feet: int = 0) -> None:
    """Does good stuff.
    
    Here's more detailed information
    on how this works.
    
    <<click-preserve-whitespace>>
    Examples:
         # basic usage
         $ myfunc
    
         # overrides
         $ myfunc --cats 1 --feet 17

    <<click-end-help>>

    Args:
        cats: Number of cats to assume prowling around.
        feet: How far cats can jump during attacks.
    """
    pass

Activity

  1. Rowlando13 commented on Apr 11, 2025

    @Rowlando13
    Member

    Click is a long standing project that has been using \b and \f for a very long time. I would suggest turning off Ruff D301 or seeing if there is a VS code setting you can alter. Is there something I am missing ? @kdeldycke

  2. added
    help outputHelp text formatting, layout, and --help rendering
    and removed on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help outputHelp text formatting, layout, and --help rendering

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions