@@ -482,6 +482,10 @@ def visit_JoinedStr(self, node):
482482 self .check_for_b907 (node )
483483 self .generic_visit (node )
484484
485+ def visit_AnnAssign (self , node ):
486+ self .check_for_b032 (node )
487+ self .generic_visit (node )
488+
485489 def check_for_b005 (self , node ):
486490 if node .func .attr not in B005 .methods :
487491 return # method name doesn't match
@@ -1235,6 +1239,21 @@ def check_for_b028(self, node):
12351239 ):
12361240 self .errors .append (B028 (node .lineno , node .col_offset ))
12371241
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+
12381257
12391258def compose_call_path (node ):
12401259 if isinstance (node , ast .Attribute ):
@@ -1625,6 +1644,13 @@ def visit_Lambda(self, node):
16251644 )
16261645)
16271646
1647+ B032 = Error (
1648+ message = (
1649+ "B032 Possible unintentional type annotation (using `:`). Did you mean to"
1650+ " assign (using `=`)?"
1651+ )
1652+ )
1653+
16281654# Warnings disabled by default.
16291655B901 = Error (
16301656 message = (
0 commit comments