Skip to content

Builtin help function unwarrantedly assumes comment in first line can always be used as summary of module #149095

@jonathandung

Description

@jonathandung

Bug report

Bug description:

The help builtin added by site, as implemented in pydoc.Helper, calls pydoc.getdoc to find documentation for an object or module, which is different than inspect.getdoc, in that it looks for comments too. This applies for modules as well, and the summary text after the hyphen in the header of the following form calls this:

package.submodule_name - blurb

The synopsis shown is gotten by pydoc.splitdoc on the output of pydoc.getdoc. An unintended side effect of this is that for a module foo without a docstring and with a file-level # type: ignore comment on the top, the following is printed as the first line of the help:

foo - type: ignore

Same goes for comments like # flake8: noqa and # mypy: disable-error-code="<error-code>".

CPython versions tested on:

3.14

Operating systems tested on:

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions