File tree 4 files changed +9
-12
lines changed
4 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -654,18 +654,15 @@ def check_for_b903(self, node):
654
654
self .errors .append (B903 (node .lineno , node .col_offset ))
655
655
656
656
def check_for_b018 (self , node ):
657
- for index , subnode in enumerate ( node .body ) :
657
+ for subnode in node .body :
658
658
if not isinstance (subnode , ast .Expr ):
659
659
continue
660
- if index == 0 and isinstance (subnode .value , ast .Str ):
661
- continue # most likely a docstring
662
660
if isinstance (
663
661
subnode .value ,
664
662
(
665
663
ast .Num ,
666
664
ast .Bytes ,
667
665
ast .NameConstant ,
668
- ast .JoinedStr ,
669
666
ast .List ,
670
667
ast .Set ,
671
668
ast .Dict ,
Original file line number Diff line number Diff line change 1
1
"""
2
2
Should emit:
3
- B018 - on lines 16 -26, 30, 33
3
+ B018 - on lines 17 -26, 30, 33
4
4
"""
5
5
6
6
@@ -12,12 +12,12 @@ class Foo2:
12
12
"""abc"""
13
13
14
14
a = 2
15
- "str" # Str
15
+ "str" # Str (no raise)
16
+ f"{ int } " # JoinedStr (no raise)
16
17
1j # Number (complex)
17
18
1 # Number (int)
18
19
1.0 # Number (float)
19
20
b"foo" # Binary
20
- f"{ int } " # JoinedStr
21
21
True # NameConstant (True)
22
22
False # NameConstant (False)
23
23
None # NameConstant (None)
Original file line number Diff line number Diff line change 1
1
"""
2
2
Should emit:
3
- B018 - on lines 15 -25, 29, 32
3
+ B018 - on lines 16 -25, 29, 32
4
4
"""
5
5
6
6
@@ -11,12 +11,12 @@ def foo1():
11
11
def foo2 ():
12
12
"""my docstring"""
13
13
a = 2
14
- "str" # Str
14
+ "str" # Str (no raise)
15
+ f"{ int } " # JoinedStr (no raise)
15
16
1j # Number (complex)
16
17
1 # Number (int)
17
18
1.0 # Number (float)
18
19
b"foo" # Binary
19
- f"{ int } " # JoinedStr
20
20
True # NameConstant (True)
21
21
False # NameConstant (False)
22
22
None # NameConstant (None)
Original file line number Diff line number Diff line change @@ -234,7 +234,7 @@ def test_b018_functions(self):
234
234
bbc = BugBearChecker (filename = str (filename ))
235
235
errors = list (bbc .run ())
236
236
237
- expected = [B018 (line , 4 ) for line in range (15 , 26 )]
237
+ expected = [B018 (line , 4 ) for line in range (16 , 26 )]
238
238
expected .append (B018 (29 , 4 ))
239
239
expected .append (B018 (32 , 4 ))
240
240
self .assertEqual (errors , self .errors (* expected ))
@@ -244,7 +244,7 @@ def test_b018_classes(self):
244
244
bbc = BugBearChecker (filename = str (filename ))
245
245
errors = list (bbc .run ())
246
246
247
- expected = [B018 (line , 4 ) for line in range (16 , 27 )]
247
+ expected = [B018 (line , 4 ) for line in range (17 , 27 )]
248
248
expected .append (B018 (30 , 4 ))
249
249
expected .append (B018 (33 , 4 ))
250
250
self .assertEqual (errors , self .errors (* expected ))
You can’t perform that action at this time.
0 commit comments