Skip to content

Commit 42e4b4b

Browse files
authored
Add typing to _determine_callable (#5548)
1 parent ddd2123 commit 42e4b4b

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

pylint/checkers/typecheck.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
from collections import deque
7070
from collections.abc import Sequence
7171
from functools import singledispatch
72-
from typing import Any, Callable, Iterator, List, Optional, Pattern, Tuple
72+
from typing import Any, Callable, Iterator, List, Optional, Pattern, Tuple, Union
7373

7474
import astroid
7575
import astroid.exceptions
@@ -100,6 +100,14 @@
100100
from pylint.interfaces import INFERENCE, IAstroidChecker
101101
from pylint.utils import get_global_option
102102

103+
CallableObjects = Union[
104+
bases.BoundMethod,
105+
bases.UnboundMethod,
106+
nodes.FunctionDef,
107+
nodes.Lambda,
108+
nodes.ClassDef,
109+
]
110+
103111
STR_FORMAT = {"builtins.str.format"}
104112
ASYNCIO_COROUTINE = "asyncio.coroutines.coroutine"
105113
BUILTIN_TUPLE = "builtins.tuple"
@@ -559,16 +567,24 @@ def _emit_no_member(
559567
return True
560568

561569

562-
def _determine_callable(callable_obj):
570+
def _determine_callable(
571+
callable_obj: nodes.NodeNG,
572+
) -> Tuple[CallableObjects, int, str]:
573+
# pylint: disable=fixme
574+
# TODO: The typing of the second return variable is actually Literal[0,1]
575+
# We need typing on astroid.NodeNG.implicit_parameters for this
576+
# TODO: The typing of the third return variable can be narrowed to a Literal
577+
# We need typing on astroid.NodeNG.type for this
578+
563579
# Ordering is important, since BoundMethod is a subclass of UnboundMethod,
564580
# and Function inherits Lambda.
565581
parameters = 0
566582
if hasattr(callable_obj, "implicit_parameters"):
567583
parameters = callable_obj.implicit_parameters()
568-
if isinstance(callable_obj, astroid.BoundMethod):
584+
if isinstance(callable_obj, bases.BoundMethod):
569585
# Bound methods have an extra implicit 'self' argument.
570586
return callable_obj, parameters, callable_obj.type
571-
if isinstance(callable_obj, astroid.UnboundMethod):
587+
if isinstance(callable_obj, bases.UnboundMethod):
572588
return callable_obj, parameters, "unbound method"
573589
if isinstance(callable_obj, nodes.FunctionDef):
574590
return callable_obj, parameters, callable_obj.type

0 commit comments

Comments
 (0)