Skip to content

Commit 3b8db00

Browse files
authored
Add some typing to astroid.inference (#1415)
1 parent 80b67a9 commit 3b8db00

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

astroid/inference.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import functools
3535
import itertools
3636
import operator
37-
from typing import Any, Callable, Dict, Iterable, Optional
37+
from typing import Any, Callable, Dict, Iterable, Iterator, Optional, Type, Union
3838

3939
import wrapt
4040

@@ -837,7 +837,7 @@ def _do_compare(
837837
>>> _do_compare([1, 3], '<=', [2, 4])
838838
util.Uninferable
839839
"""
840-
retval = None
840+
retval: Union[None, bool] = None
841841
if op in UNINFERABLE_OPS:
842842
return util.Uninferable
843843
op_func = COMPARE_OPS[op]
@@ -862,14 +862,15 @@ def _do_compare(
862862
return util.Uninferable
863863
# (or both, but "True | False" is basically the same)
864864

865+
assert retval is not None
865866
return retval # it was all the same value
866867

867868

868869
def _infer_compare(
869870
self: nodes.Compare, context: Optional[InferenceContext] = None
870-
) -> Any:
871+
) -> Iterator[Union[nodes.Const, Type[util.Uninferable]]]:
871872
"""Chained comparison inference logic."""
872-
retval = True
873+
retval: Union[bool, Type[util.Uninferable]] = True
873874

874875
ops = self.ops
875876
left_node = self.left
@@ -887,7 +888,7 @@ def _infer_compare(
887888
break # short-circuit
888889
lhs = rhs # continue
889890
if retval is util.Uninferable:
890-
yield retval
891+
yield retval # type: ignore[misc]
891892
else:
892893
yield nodes.Const(retval)
893894

0 commit comments

Comments
 (0)