Skip to content

B018 complains about f-strings as docstrings... and it's right! (but a more specific message would be helpful) #211

@Zac-HD

Description

@Zac-HD
CONSTANT = "magic value"

def f():
    f"""Return {CONSTANT!r}."""  # warning B018
    return CONSTANT

assert f.__doc__ is not None  # fails!

I was originally reporting this as a bug, but it turns out that f-strings don't work as docstrings! IMO this deserves to be split out into a new B019 check with a more specific message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions