@@ -1381,24 +1381,26 @@ def postinit(self, target: Name | Attribute | Subscript, value: NodeNG) -> None:
13811381 See astroid/protocols.py for actual implementation.
13821382 """
13831383
1384- def type_errors (self , context : InferenceContext | None = None ):
1384+ def type_errors (
1385+ self , context : InferenceContext | None = None
1386+ ) -> list [util .BadBinaryOperationMessage ]:
13851387 """Get a list of type errors which can occur during inference.
13861388
13871389 Each TypeError is represented by a :class:`BadBinaryOperationMessage` ,
13881390 which holds the original exception.
13891391
1390- :returns: The list of possible type errors.
1391- :rtype: list(BadBinaryOperationMessage)
1392+ If any inferred result is uninferable, an empty list is returned.
13921393 """
1394+ bad = []
13931395 try :
1394- results = self ._infer_augassign (context = context )
1395- return [
1396- result
1397- for result in results
1398- if isinstance (result , util .BadBinaryOperationMessage )
1399- ]
1396+ for result in self ._infer_augassign (context = context ):
1397+ if result is util .Uninferable :
1398+ raise InferenceError
1399+ if isinstance (result , util .BadBinaryOperationMessage ):
1400+ bad .append (result )
14001401 except InferenceError :
14011402 return []
1403+ return bad
14021404
14031405 def get_children (self ):
14041406 yield self .target
@@ -1497,24 +1499,26 @@ def postinit(self, left: NodeNG, right: NodeNG) -> None:
14971499 self .left = left
14981500 self .right = right
14991501
1500- def type_errors (self , context : InferenceContext | None = None ):
1502+ def type_errors (
1503+ self , context : InferenceContext | None = None
1504+ ) -> list [util .BadBinaryOperationMessage ]:
15011505 """Get a list of type errors which can occur during inference.
15021506
15031507 Each TypeError is represented by a :class:`BadBinaryOperationMessage`,
15041508 which holds the original exception.
15051509
1506- :returns: The list of possible type errors.
1507- :rtype: list(BadBinaryOperationMessage)
1510+ If any inferred result is uninferable, an empty list is returned.
15081511 """
1512+ bad = []
15091513 try :
1510- results = self ._infer_binop (context = context )
1511- return [
1512- result
1513- for result in results
1514- if isinstance (result , util .BadBinaryOperationMessage )
1515- ]
1514+ for result in self ._infer_binop (context = context ):
1515+ if result is util .Uninferable :
1516+ raise InferenceError
1517+ if isinstance (result , util .BadBinaryOperationMessage ):
1518+ bad .append (result )
15161519 except InferenceError :
15171520 return []
1521+ return bad
15181522
15191523 def get_children (self ):
15201524 yield self .left
@@ -4262,24 +4266,26 @@ def __init__(
42624266 def postinit (self , operand : NodeNG ) -> None :
42634267 self .operand = operand
42644268
4265- def type_errors (self , context : InferenceContext | None = None ):
4269+ def type_errors (
4270+ self , context : InferenceContext | None = None
4271+ ) -> list [util .BadUnaryOperationMessage ]:
42664272 """Get a list of type errors which can occur during inference.
42674273
42684274 Each TypeError is represented by a :class:`BadUnaryOperationMessage`,
42694275 which holds the original exception.
42704276
4271- :returns: The list of possible type errors.
4272- :rtype: list(BadUnaryOperationMessage)
4277+ If any inferred result is uninferable, an empty list is returned.
42734278 """
4279+ bad = []
42744280 try :
4275- results = self ._infer_unaryop (context = context )
4276- return [
4277- result
4278- for result in results
4279- if isinstance (result , util .BadUnaryOperationMessage )
4280- ]
4281+ for result in self ._infer_unaryop (context = context ):
4282+ if result is util .Uninferable :
4283+ raise InferenceError
4284+ if isinstance (result , util .BadUnaryOperationMessage ):
4285+ bad .append (result )
42814286 except InferenceError :
42824287 return []
4288+ return bad
42834289
42844290 def get_children (self ):
42854291 yield self .operand
0 commit comments