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

Discussion:

Patch:
diff --git a/bugbear.py b/bugbear.py
index 77b4dc6..9249550 100644
--- a/bugbear.py
+++ b/bugbear.py
@@ -639,7 +639,6 @@ class BugBearVisitor(ast.NodeVisitor):
             if isinstance(
                 subnode.value,
                 (
-                    ast.Str,
                     ast.Num,
                     ast.Bytes,
                     ast.NameConstant,


Test patch:
diff --git a/tests/b018_classes.py b/tests/b018_classes.py
index 12195c0..551b14e 100644
--- a/tests/b018_classes.py
+++ b/tests/b018_classes.py
@@ -1,6 +1,6 @@
 """
 Should emit:
-B018 - on lines 15-26, 30, 32
+B018 - on lines 16-26, 30, 33
 """
 
 
@@ -30,3 +30,4 @@ class Foo3:
     123
     a = 2
     "str"
+    1
diff --git a/tests/b018_functions.py b/tests/b018_functions.py
index 9764274..f8c3f77 100644
--- a/tests/b018_functions.py
+++ b/tests/b018_functions.py
@@ -1,6 +1,6 @@
 """
 Should emit:
-B018 - on lines 14-25, 29, 31
+B018 - on lines 15-25, 29, 32
 """
 
 
@@ -29,3 +29,4 @@ def foo3():
     123
     a = 2
     "str"
+    3
diff --git a/tests/test_bugbear.py b/tests/test_bugbear.py
index c05b828..319a508 100644
--- a/tests/test_bugbear.py
+++ b/tests/test_bugbear.py
@@ -234,9 +234,9 @@ class BugbearTestCase(unittest.TestCase):
         bbc = BugBearChecker(filename=str(filename))
         errors = list(bbc.run())
 
-        expected = [B018(line, 4) for line in range(14, 26)]
+        expected = [B018(line, 4) for line in range(15, 26)]
         expected.append(B018(29, 4))
-        expected.append(B018(31, 4))
+        expected.append(B018(32, 4))
         self.assertEqual(errors, self.errors(*expected))
 
     def test_b018_classes(self):
@@ -244,9 +244,9 @@ class BugbearTestCase(unittest.TestCase):
         bbc = BugBearChecker(filename=str(filename))
         errors = list(bbc.run())
 
-        expected = [B018(line, 4) for line in range(15, 27)]
+        expected = [B018(line, 4) for line in range(16, 27)]
         expected.append(B018(30, 4))
-        expected.append(B018(32, 4))
+        expected.append(B018(33, 4))
         self.assertEqual(errors, self.errors(*expected))
 
     def test_b901(self):