|
69 | 69 | from collections import deque
|
70 | 70 | from collections.abc import Sequence
|
71 | 71 | 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 |
73 | 73 |
|
74 | 74 | import astroid
|
75 | 75 | import astroid.exceptions
|
|
100 | 100 | from pylint.interfaces import INFERENCE, IAstroidChecker
|
101 | 101 | from pylint.utils import get_global_option
|
102 | 102 |
|
| 103 | +CallableObjects = Union[ |
| 104 | + bases.BoundMethod, |
| 105 | + bases.UnboundMethod, |
| 106 | + nodes.FunctionDef, |
| 107 | + nodes.Lambda, |
| 108 | + nodes.ClassDef, |
| 109 | +] |
| 110 | + |
103 | 111 | STR_FORMAT = {"builtins.str.format"}
|
104 | 112 | ASYNCIO_COROUTINE = "asyncio.coroutines.coroutine"
|
105 | 113 | BUILTIN_TUPLE = "builtins.tuple"
|
@@ -559,16 +567,24 @@ def _emit_no_member(
|
559 | 567 | return True
|
560 | 568 |
|
561 | 569 |
|
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 | + |
563 | 579 | # Ordering is important, since BoundMethod is a subclass of UnboundMethod,
|
564 | 580 | # and Function inherits Lambda.
|
565 | 581 | parameters = 0
|
566 | 582 | if hasattr(callable_obj, "implicit_parameters"):
|
567 | 583 | parameters = callable_obj.implicit_parameters()
|
568 |
| - if isinstance(callable_obj, astroid.BoundMethod): |
| 584 | + if isinstance(callable_obj, bases.BoundMethod): |
569 | 585 | # Bound methods have an extra implicit 'self' argument.
|
570 | 586 | return callable_obj, parameters, callable_obj.type
|
571 |
| - if isinstance(callable_obj, astroid.UnboundMethod): |
| 587 | + if isinstance(callable_obj, bases.UnboundMethod): |
572 | 588 | return callable_obj, parameters, "unbound method"
|
573 | 589 | if isinstance(callable_obj, nodes.FunctionDef):
|
574 | 590 | return callable_obj, parameters, callable_obj.type
|
|
0 commit comments