@@ -510,18 +510,28 @@ def _infer_boolop(
510
510
# UnaryOp, BinOp and AugAssign inferences
511
511
512
512
513
- def _filter_operation_errors (self , infer_callable , context , error ):
513
+ def _filter_operation_errors (
514
+ self : _T ,
515
+ infer_callable : Callable [
516
+ [_T , InferenceContext | None ],
517
+ Generator [InferenceResult | util .BadOperationMessage , None , None ],
518
+ ],
519
+ context : InferenceContext | None ,
520
+ error : type [util .BadOperationMessage ],
521
+ ) -> Generator [InferenceResult , None , None ]:
514
522
for result in infer_callable (self , context ):
515
523
if isinstance (result , error ):
516
524
# For the sake of .infer(), we don't care about operation
517
525
# errors, which is the job of pylint. So return something
518
526
# which shows that we can't infer the result.
519
527
yield util .Uninferable
520
528
else :
521
- yield result
529
+ yield result # type: ignore[misc]
522
530
523
531
524
- def _infer_unaryop (self , context = None ):
532
+ def _infer_unaryop (
533
+ self : nodes .UnaryOp , context : InferenceContext | None = None
534
+ ) -> Generator [InferenceResult | util .BadUnaryOperationMessage , None , None ]:
525
535
"""Infer what an UnaryOp should return when evaluated."""
526
536
for operand in self .operand .infer (context ):
527
537
try :
@@ -579,16 +589,18 @@ def _infer_unaryop(self, context=None):
579
589
580
590
@decorators .raise_if_nothing_inferred
581
591
@decorators .path_wrapper
582
- def infer_unaryop (self , context = None ):
592
+ def infer_unaryop (
593
+ self : nodes .UnaryOp , context : InferenceContext | None = None , ** kwargs : Any
594
+ ) -> Generator [InferenceResult , None , InferenceErrorInfo ]:
583
595
"""Infer what an UnaryOp should return when evaluated."""
584
596
yield from _filter_operation_errors (
585
597
self , _infer_unaryop , context , util .BadUnaryOperationMessage
586
598
)
587
- return dict (node = self , context = context )
599
+ return InferenceErrorInfo (node = self , context = context )
588
600
589
601
590
602
nodes .UnaryOp ._infer_unaryop = _infer_unaryop
591
- nodes .UnaryOp ._infer = infer_unaryop
603
+ nodes .UnaryOp ._infer = infer_unaryop # type: ignore[assignment]
592
604
593
605
594
606
def _is_not_implemented (const ):
@@ -828,7 +840,9 @@ def _infer_binary_operation(left, right, binary_opnode, context, flow_factory):
828
840
yield util .BadBinaryOperationMessage (left_type , binary_opnode .op , right_type )
829
841
830
842
831
- def _infer_binop (self , context ):
843
+ def _infer_binop (
844
+ self : nodes .BinOp , context : InferenceContext | None = None
845
+ ) -> Generator [InferenceResult | util .BadBinaryOperationMessage , None , None ]:
832
846
"""Binary operation inference logic."""
833
847
left = self .left
834
848
right = self .right
@@ -855,14 +869,16 @@ def _infer_binop(self, context):
855
869
856
870
@decorators .yes_if_nothing_inferred
857
871
@decorators .path_wrapper
858
- def infer_binop (self , context = None ):
872
+ def infer_binop (
873
+ self : nodes .BinOp , context : InferenceContext | None = None , ** kwargs : Any
874
+ ) -> Generator [InferenceResult , None , None ]:
859
875
return _filter_operation_errors (
860
876
self , _infer_binop , context , util .BadBinaryOperationMessage
861
877
)
862
878
863
879
864
880
nodes .BinOp ._infer_binop = _infer_binop
865
- nodes .BinOp ._infer = infer_binop
881
+ nodes .BinOp ._infer = infer_binop # type: ignore[assignment]
866
882
867
883
COMPARE_OPS : dict [str , Callable [[Any , Any ], bool ]] = {
868
884
"==" : operator .eq ,
@@ -932,8 +948,8 @@ def _do_compare(
932
948
933
949
934
950
def _infer_compare (
935
- self : nodes .Compare , context : InferenceContext | None = None
936
- ) -> Iterator [nodes .Const | type [util .Uninferable ]]:
951
+ self : nodes .Compare , context : InferenceContext | None = None , ** kwargs : Any
952
+ ) -> Generator [nodes .Const | type [util .Uninferable ], None , None ]:
937
953
"""Chained comparison inference logic."""
938
954
retval : bool | type [util .Uninferable ] = True
939
955
@@ -961,7 +977,9 @@ def _infer_compare(
961
977
nodes .Compare ._infer = _infer_compare # type: ignore[assignment]
962
978
963
979
964
- def _infer_augassign (self , context = None ):
980
+ def _infer_augassign (
981
+ self : nodes .AugAssign , context : InferenceContext | None = None
982
+ ) -> Generator [InferenceResult | util .BadBinaryOperationMessage , None , None ]:
965
983
"""Inference logic for augmented binary operations."""
966
984
context = context or InferenceContext ()
967
985
@@ -989,14 +1007,16 @@ def _infer_augassign(self, context=None):
989
1007
990
1008
@decorators .raise_if_nothing_inferred
991
1009
@decorators .path_wrapper
992
- def infer_augassign (self , context = None ):
1010
+ def infer_augassign (
1011
+ self : nodes .AugAssign , context : InferenceContext | None = None , ** kwargs : Any
1012
+ ) -> Generator [InferenceResult , None , None ]:
993
1013
return _filter_operation_errors (
994
1014
self , _infer_augassign , context , util .BadBinaryOperationMessage
995
1015
)
996
1016
997
1017
998
1018
nodes .AugAssign ._infer_augassign = _infer_augassign
999
- nodes .AugAssign ._infer = infer_augassign
1019
+ nodes .AugAssign ._infer = infer_augassign # type: ignore[assignment]
1000
1020
1001
1021
# End of binary operation inference.
1002
1022
0 commit comments