@@ -1380,24 +1380,26 @@ def postinit(self, target: Name | Attribute | Subscript, value: NodeNG) -> None:
13801380 See astroid/protocols.py for actual implementation.
13811381 """
13821382
1383- def type_errors (self , context : InferenceContext | None = None ):
1383+ def type_errors (
1384+ self , context : InferenceContext | None = None
1385+ ) -> list [util .BadBinaryOperationMessage ]:
13841386 """Get a list of type errors which can occur during inference.
13851387
13861388 Each TypeError is represented by a :class:`BadBinaryOperationMessage` ,
13871389 which holds the original exception.
13881390
1389- :returns: The list of possible type errors.
1390- :rtype: list(BadBinaryOperationMessage)
1391+ If any inferred result is uninferable, an empty list is returned.
13911392 """
1393+ bad = []
13921394 try :
1393- results = self ._infer_augassign (context = context )
1394- return [
1395- result
1396- for result in results
1397- if isinstance (result , util .BadBinaryOperationMessage )
1398- ]
1395+ for result in self ._infer_augassign (context = context ):
1396+ if result is util .Uninferable :
1397+ raise InferenceError
1398+ if isinstance (result , util .BadBinaryOperationMessage ):
1399+ bad .append (result )
13991400 except InferenceError :
14001401 return []
1402+ return bad
14011403
14021404 def get_children (self ):
14031405 yield self .target
@@ -1496,24 +1498,26 @@ def postinit(self, left: NodeNG, right: NodeNG) -> None:
14961498 self .left = left
14971499 self .right = right
14981500
1499- def type_errors (self , context : InferenceContext | None = None ):
1501+ def type_errors (
1502+ self , context : InferenceContext | None = None
1503+ ) -> list [util .BadBinaryOperationMessage ]:
15001504 """Get a list of type errors which can occur during inference.
15011505
15021506 Each TypeError is represented by a :class:`BadBinaryOperationMessage`,
15031507 which holds the original exception.
15041508
1505- :returns: The list of possible type errors.
1506- :rtype: list(BadBinaryOperationMessage)
1509+ If any inferred result is uninferable, an empty list is returned.
15071510 """
1511+ bad = []
15081512 try :
1509- results = self ._infer_binop (context = context )
1510- return [
1511- result
1512- for result in results
1513- if isinstance (result , util .BadBinaryOperationMessage )
1514- ]
1513+ for result in self ._infer_binop (context = context ):
1514+ if result is util .Uninferable :
1515+ raise InferenceError
1516+ if isinstance (result , util .BadBinaryOperationMessage ):
1517+ bad .append (result )
15151518 except InferenceError :
15161519 return []
1520+ return bad
15171521
15181522 def get_children (self ):
15191523 yield self .left
@@ -4261,24 +4265,26 @@ def __init__(
42614265 def postinit (self , operand : NodeNG ) -> None :
42624266 self .operand = operand
42634267
4264- def type_errors (self , context : InferenceContext | None = None ):
4268+ def type_errors (
4269+ self , context : InferenceContext | None = None
4270+ ) -> list [util .BadUnaryOperationMessage ]:
42654271 """Get a list of type errors which can occur during inference.
42664272
42674273 Each TypeError is represented by a :class:`BadUnaryOperationMessage`,
42684274 which holds the original exception.
42694275
4270- :returns: The list of possible type errors.
4271- :rtype: list(BadUnaryOperationMessage)
4276+ If any inferred result is uninferable, an empty list is returned.
42724277 """
4278+ bad = []
42734279 try :
4274- results = self ._infer_unaryop (context = context )
4275- return [
4276- result
4277- for result in results
4278- if isinstance (result , util .BadUnaryOperationMessage )
4279- ]
4280+ for result in self ._infer_unaryop (context = context ):
4281+ if result is util .Uninferable :
4282+ raise InferenceError
4283+ if isinstance (result , util .BadUnaryOperationMessage ):
4284+ bad .append (result )
42804285 except InferenceError :
42814286 return []
4287+ return bad
42824288
42834289 def get_children (self ):
42844290 yield self .operand
0 commit comments