@@ -482,6 +482,10 @@ def visit_JoinedStr(self, node):
482
482
self .check_for_b907 (node )
483
483
self .generic_visit (node )
484
484
485
+ def visit_AnnAssign (self , node ):
486
+ self .check_for_b032 (node )
487
+ self .generic_visit (node )
488
+
485
489
def check_for_b005 (self , node ):
486
490
if node .func .attr not in B005 .methods :
487
491
return # method name doesn't match
@@ -1235,6 +1239,21 @@ def check_for_b028(self, node):
1235
1239
):
1236
1240
self .errors .append (B028 (node .lineno , node .col_offset ))
1237
1241
1242
+ def check_for_b032 (self , node ):
1243
+ if (
1244
+ node .value is None
1245
+ and hasattr (node .target , "value" )
1246
+ and isinstance (node .target .value , ast .Name )
1247
+ and (
1248
+ isinstance (node .target , ast .Subscript )
1249
+ or (
1250
+ isinstance (node .target , ast .Attribute )
1251
+ and node .target .value .id != "self"
1252
+ )
1253
+ )
1254
+ ):
1255
+ self .errors .append (B032 (node .lineno , node .col_offset ))
1256
+
1238
1257
1239
1258
def compose_call_path (node ):
1240
1259
if isinstance (node , ast .Attribute ):
@@ -1625,6 +1644,13 @@ def visit_Lambda(self, node):
1625
1644
)
1626
1645
)
1627
1646
1647
+ B032 = Error (
1648
+ message = (
1649
+ "B032 Possible unintentional type annotation (using `:`). Did you mean to"
1650
+ " assign (using `=`)?"
1651
+ )
1652
+ )
1653
+
1628
1654
# Warnings disabled by default.
1629
1655
B901 = Error (
1630
1656
message = (
0 commit comments