Skip to content

pydoc renders the parameter descriptions of some C functions with a different indentation #155236

Description

@serhiy-storchaka

Bug report

bytes.rsplit is a clone of bytes.split, their docstrings contain the same description of sep, but pydoc renders them differently:

 |  split(self, /, sep=None, maxsplit=-1)     |  rsplit(self, /, sep=None, maxsplit=-1)
 |      Return a list of the sections ...     |      Return a list of the sections ...
 |                                            |
 |      sep                                   |        sep
 |        The delimiter according which ...   |          The delimiter according which ...

The docstring of split ends with the parameter descriptions, so the smallest indentation of all lines after the first one is 2, and inspect.cleandoc() removes it. The docstring of rsplit has one more paragraph which starts at the column 0, so nothing is removed.

As a result the same description is 2 characters wider in rsplit, and rewrapping it in split does not help.

69 of the documentation strings which contain an indented block are dedented, and 97 are not.

Since 3.13 the compiler removes the indentation of docstrings written in the source code (#81283), so the dedenting in cleandoc() now only affects documentation strings where the indentation is meaningful, like those generated by Argument Clinic.

I propose to add a dedent parameter in inspect.cleandoc() and inspect.getdoc(), and to not dedent in pydoc.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesdocsDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions