flake8-bugbear: B018 wrongly detects inline variable or attribute docstrings

Having an inline attribute doc string or a module variable docstring, it is wrongly marked as B018 (sample from sphinx doc):

module_level_variable2 = 98765
"""int: Module level variable documented inline.

The docstring may span multiple lines. The type may optionally be specified
on the first line, separated by a colon.
"""

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 8
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

21.11.29 released reverting checking of strings for now. We will work on adding some pattern matching support into the string detection and probably default to ignoring this edge use case.

I also, 21.11.28 yanked from PyPI so it can not be installed to create noise.

Wow, that was fast!

@cooperlees @kasium Thx a lot!

My fault. The ignore was only for strings and not for f-strings (aka JoinedStr). PR is open

For info, attribute docstrings aren’t a Python feature, however, are widely used and supported by the Sphinx documentation system via autodoc.