Repository: PyCQA/flake8-bugbear

Issue:
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.
"""

```

Comments:

Patch:
diff --git a/bugbear.py b/bugbear.py
index 78c2ca3..b8ecbd5 100644
--- a/bugbear.py
+++ b/bugbear.py
@@ -654,18 +654,15 @@ class BugBearVisitor(ast.NodeVisitor):
         self.errors.append(B903(node.lineno, node.col_offset))
 
     def check_for_b018(self, node):
-        for index, subnode in enumerate(node.body):
+        for subnode in node.body:
             if not isinstance(subnode, ast.Expr):
                 continue
-            if index == 0 and isinstance(subnode.value, ast.Str):
-                continue  # most likely a docstring
             if isinstance(
                 subnode.value,
                 (
                     ast.Num,
                     ast.Bytes,
                     ast.NameConstant,
-                    ast.JoinedStr,
                     ast.List,
                     ast.Set,
                     ast.Dict,


Test patch:
diff --git a/tests/b018_classes.py b/tests/b018_classes.py
index 551b14e..7992f15 100644
--- a/tests/b018_classes.py
+++ b/tests/b018_classes.py
@@ -1,6 +1,6 @@
 """
 Should emit:
-B018 - on lines 16-26, 30, 33
+B018 - on lines 17-26, 30, 33
 """
 
 
@@ -12,12 +12,12 @@ class Foo2:
     """abc"""
 
     a = 2
-    "str"  # Str
+    "str"  # Str (no raise)
+    f"{int}"  # JoinedStr (no raise)
     1j  # Number (complex)
     1  # Number (int)
     1.0  # Number (float)
     b"foo"  # Binary
-    f"{int}"  # JoinedStr
     True  # NameConstant (True)
     False  # NameConstant (False)
     None  # NameConstant (None)
diff --git a/tests/b018_functions.py b/tests/b018_functions.py
index f8c3f77..763d6b8 100644
--- a/tests/b018_functions.py
+++ b/tests/b018_functions.py
@@ -1,6 +1,6 @@
 """
 Should emit:
-B018 - on lines 15-25, 29, 32
+B018 - on lines 16-25, 29, 32
 """
 
 
@@ -11,12 +11,12 @@ def foo1():
 def foo2():
     """my docstring"""
     a = 2
-    "str"  # Str
+    "str"  # Str (no raise)
+    f"{int}"  # JoinedStr (no raise)
     1j  # Number (complex)
     1  # Number (int)
     1.0  # Number (float)
     b"foo"  # Binary
-    f"{int}"  # JoinedStr
     True  # NameConstant (True)
     False  # NameConstant (False)
     None  # NameConstant (None)
diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py
index d1af992..d02b637 100644
--- a/tests/test_bugbear.py
+++ b/tests/test_bugbear.py
@@ -234,7 +234,7 @@ class BugbearTestCase(unittest.TestCase):
         bbc = BugBearChecker(filename=str(filename))
         errors = list(bbc.run())
 
-        expected = [B018(line, 4) for line in range(15, 26)]
+        expected = [B018(line, 4) for line in range(16, 26)]
         expected.append(B018(29, 4))
         expected.append(B018(32, 4))
         self.assertEqual(errors, self.errors(*expected))
@@ -244,7 +244,7 @@ class BugbearTestCase(unittest.TestCase):
         bbc = BugBearChecker(filename=str(filename))
         errors = list(bbc.run())
 
-        expected = [B018(line, 4) for line in range(16, 27)]
+        expected = [B018(line, 4) for line in range(17, 27)]
         expected.append(B018(30, 4))
         expected.append(B018(33, 4))
         self.assertEqual(errors, self.errors(*expected))