@@ -198,7 +198,9 @@ class ExceptionRaiseRefVisitor(BaseVisitor):
198198
199199 def visit_name (self , node : nodes .Name ) -> None :
200200 if node .name == "NotImplemented" :
201- self ._checker .add_message ("notimplemented-raised" , node = self ._node )
201+ self ._checker .add_message (
202+ "notimplemented-raised" , node = self ._node , confidence = HIGH
203+ )
202204 elif node .name in OVERGENERAL_EXCEPTIONS :
203205 self ._checker .add_message (
204206 "broad-exception-raised" ,
@@ -217,15 +219,20 @@ def visit_call(self, node: nodes.Call) -> None:
217219 ):
218220 msg = node .args [0 ].value
219221 if "%" in msg or ("{" in msg and "}" in msg ):
220- self ._checker .add_message ("raising-format-tuple" , node = self ._node )
222+ self ._checker .add_message (
223+ "raising-format-tuple" , node = self ._node , confidence = HIGH
224+ )
221225
222226
223227class ExceptionRaiseLeafVisitor (BaseVisitor ):
224228 """Visitor for handling leaf kinds of a raise value."""
225229
226230 def visit_const (self , node : nodes .Const ) -> None :
227231 self ._checker .add_message (
228- "raising-bad-type" , node = self ._node , args = node .value .__class__ .__name__
232+ "raising-bad-type" ,
233+ node = self ._node ,
234+ args = node .value .__class__ .__name__ ,
235+ confidence = INFERENCE ,
229236 )
230237
231238 def visit_instance (self , instance : objects .ExceptionInstance ) -> None :
@@ -238,14 +245,28 @@ def visit_instance(self, instance: objects.ExceptionInstance) -> None:
238245 def visit_classdef (self , node : nodes .ClassDef ) -> None :
239246 if not utils .inherit_from_std_ex (node ) and utils .has_known_bases (node ):
240247 if node .newstyle :
241- self ._checker .add_message ("raising-non-exception" , node = self ._node )
248+ self ._checker .add_message (
249+ "raising-non-exception" ,
250+ node = self ._node ,
251+ confidence = INFERENCE ,
252+ )
242253
243254 def visit_tuple (self , _ : nodes .Tuple ) -> None :
244- self ._checker .add_message ("raising-bad-type" , node = self ._node , args = "tuple" )
255+ self ._checker .add_message (
256+ "raising-bad-type" ,
257+ node = self ._node ,
258+ args = "tuple" ,
259+ confidence = INFERENCE ,
260+ )
245261
246262 def visit_default (self , node : nodes .NodeNG ) -> None :
247263 name = getattr (node , "name" , node .__class__ .__name__ )
248- self ._checker .add_message ("raising-bad-type" , node = self ._node , args = name )
264+ self ._checker .add_message (
265+ "raising-bad-type" ,
266+ node = self ._node ,
267+ args = name ,
268+ confidence = INFERENCE ,
269+ )
249270
250271
251272class ExceptionsChecker (checkers .BaseChecker ):
@@ -316,7 +337,7 @@ def _check_misplaced_bare_raise(self, node: nodes.Raise) -> None:
316337
317338 expected = (nodes .ExceptHandler ,)
318339 if not current or not isinstance (current .parent , expected ):
319- self .add_message ("misplaced-bare-raise" , node = node )
340+ self .add_message ("misplaced-bare-raise" , node = node , confidence = HIGH )
320341
321342 def _check_bad_exception_cause (self , node : nodes .Raise ) -> None :
322343 """Verify that the exception cause is properly set.
@@ -522,17 +543,22 @@ def visit_tryexcept(self, node: nodes.TryExcept) -> None:
522543 for index , handler in enumerate (node .handlers ):
523544 if handler .type is None :
524545 if not _is_raising (handler .body ):
525- self .add_message ("bare-except" , node = handler )
546+ self .add_message ("bare-except" , node = handler , confidence = HIGH )
526547
527548 # check if an "except:" is followed by some other
528549 # except
529550 if index < (nb_handlers - 1 ):
530551 msg = "empty except clause should always appear last"
531- self .add_message ("bad-except-order" , node = node , args = msg )
552+ self .add_message (
553+ "bad-except-order" , node = node , args = msg , confidence = HIGH
554+ )
532555
533556 elif isinstance (handler .type , nodes .BoolOp ):
534557 self .add_message (
535- "binary-op-exception" , node = handler , args = handler .type .op
558+ "binary-op-exception" ,
559+ node = handler ,
560+ args = handler .type .op ,
561+ confidence = HIGH ,
536562 )
537563 else :
538564 try :
@@ -561,7 +587,10 @@ def visit_tryexcept(self, node: nodes.TryExcept) -> None:
561587 if previous_exc in exc_ancestors :
562588 msg = f"{ previous_exc .name } is an ancestor class of { exception .name } "
563589 self .add_message (
564- "bad-except-order" , node = handler .type , args = msg
590+ "bad-except-order" ,
591+ node = handler .type ,
592+ args = msg ,
593+ confidence = INFERENCE ,
565594 )
566595 if (
567596 exception .name in self .linter .config .overgeneral_exceptions
@@ -572,11 +601,15 @@ def visit_tryexcept(self, node: nodes.TryExcept) -> None:
572601 "broad-exception-caught" ,
573602 args = exception .name ,
574603 node = handler .type ,
604+ confidence = INFERENCE ,
575605 )
576606
577607 if exception in exceptions_classes :
578608 self .add_message (
579- "duplicate-except" , args = exception .name , node = handler .type
609+ "duplicate-except" ,
610+ args = exception .name ,
611+ node = handler .type ,
612+ confidence = INFERENCE ,
580613 )
581614
582615 exceptions_classes += [exc for _ , exc in exceptions ]
0 commit comments