Skip to content

Warn about invalid string type for docstring #1603

Closed
@orsinium

Description

Rule request

Thesis

F-strings and bytes cannot be used as a docstring (raw strings is ok). For example:

def ab(a, b):
  f"""oh hi
  """
  return a+b

In the example above, neither inspect.getdoc nor ast.get_docstring will interpret the f-string as a docstring.

Also, get_docstring is a good reference for the check implementation: https://github.com/python/cpython/blob/3.8/Lib/ast.py#L236-L259

Reasoning

It's a bug. Once I tried to use an f-string-based docstring to reuse something inside because we use docstrings to generate OpenAPI spec. Turned out it doesn't work.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions