34
34
import functools
35
35
import itertools
36
36
import operator
37
- from typing import Any , Callable , Dict , Iterable , Optional
37
+ from typing import Any , Callable , Dict , Iterable , Iterator , Optional , Type , Union
38
38
39
39
import wrapt
40
40
@@ -837,7 +837,7 @@ def _do_compare(
837
837
>>> _do_compare([1, 3], '<=', [2, 4])
838
838
util.Uninferable
839
839
"""
840
- retval = None
840
+ retval : Union [ None , bool ] = None
841
841
if op in UNINFERABLE_OPS :
842
842
return util .Uninferable
843
843
op_func = COMPARE_OPS [op ]
@@ -862,14 +862,15 @@ def _do_compare(
862
862
return util .Uninferable
863
863
# (or both, but "True | False" is basically the same)
864
864
865
+ assert retval is not None
865
866
return retval # it was all the same value
866
867
867
868
868
869
def _infer_compare (
869
870
self : nodes .Compare , context : Optional [InferenceContext ] = None
870
- ) -> Any :
871
+ ) -> Iterator [ Union [ nodes . Const , Type [ util . Uninferable ]]] :
871
872
"""Chained comparison inference logic."""
872
- retval = True
873
+ retval : Union [ bool , Type [ util . Uninferable ]] = True
873
874
874
875
ops = self .ops
875
876
left_node = self .left
@@ -887,7 +888,7 @@ def _infer_compare(
887
888
break # short-circuit
888
889
lhs = rhs # continue
889
890
if retval is util .Uninferable :
890
- yield retval
891
+ yield retval # type: ignore[misc]
891
892
else :
892
893
yield nodes .Const (retval )
893
894
0 commit comments