Skip to content

Google first-line is being wrapped 2 chars shorter than the rest #32

Description

@AgentRev

The following docstring

class FooBar:
    """Abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc.

    Abcabc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc.
    """
    pass

strangely gets formatted to

class FooBar:
    """Abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc
    abc.

    Abcabc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc.
    """
    pass

The problem appears to come from

# Google docstrings can preserve string prefixes such as ``rf`` when rebuilt,
# so first-line wrapping reserves two prefix characters plus opening quotes.
GOOGLE_OPENING_QUOTES_WIDTH: Final[int] = 5
GOOGLE_COMPACT_OPENING_QUOTES_WIDTH: Final[int] = 5

which contradicts

if isinstance(val, ast.Constant) and isinstance(val.value, str):

because f prefixed strings are of type ast.JoinedStr and not ast.Constant, and thus never satisfy the condition to count as docstrings.

b and u prefixed strings, while of ast.Constant type, do not seem to get formatted either, albeit for a different reason.


Easy solution, just sweep prefixed docstrings under the rug, and change the constants to:

# First-line wrapping reserves 3 opening quotes. 
GOOGLE_OPENING_QUOTES_WIDTH: Final[int] = 3
GOOGLE_COMPACT_OPENING_QUOTES_WIDTH: Final[int] = 3

No activity

Activity on this issue will appear here.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions