diff options
Diffstat (limited to 'astroid')
-rw-r--r-- | astroid/arguments.py | 22 | ||||
-rw-r--r-- | astroid/brain/brain_namedtuple_enum.py | 4 | ||||
-rw-r--r-- | astroid/exceptions.py | 2 |
3 files changed, 18 insertions, 10 deletions
diff --git a/astroid/arguments.py b/astroid/arguments.py index 0096cee2..f2630416 100644 --- a/astroid/arguments.py +++ b/astroid/arguments.py @@ -9,6 +9,7 @@ from astroid.bases import Instance from astroid.context import CallContext, InferenceContext from astroid.exceptions import InferenceError, NoDefault from astroid.helpers import safe_infer +from astroid.typing import InferenceResult from astroid.util import Uninferable, UninferableBase @@ -134,14 +135,19 @@ class CallSite: values.append(arg) return values - def infer_argument(self, funcnode, name, context): # noqa: C901 - """Infer a function argument value according to the call context. + def infer_argument( + self, funcnode: InferenceResult, name: str, context: InferenceContext + ): # noqa: C901 + """Infer a function argument value according to the call context.""" + if not isinstance(funcnode, (nodes.FunctionDef, nodes.Lambda)): + raise InferenceError( + f"Can not infer function argument value for non-function node {funcnode!r}.", + call_site=self, + func=funcnode, + arg=name, + context=context, + ) - Arguments: - funcnode: The function being called. - name: The name of the argument whose value is being inferred. - context: Inference context object - """ if name in self.duplicated_keywords: raise InferenceError( "The arguments passed to {func!r} have duplicate keywords.", @@ -191,7 +197,7 @@ class CallSite: positional.append(arg) if argindex is not None: - boundnode = getattr(context, "boundnode", None) + boundnode = context.boundnode # 2. first argument of instance/class method if argindex == 0 and funcnode.type in {"method", "classmethod"}: # context.boundnode is None when an instance method is called with diff --git a/astroid/brain/brain_namedtuple_enum.py b/astroid/brain/brain_namedtuple_enum.py index 2af99017..18aedcb3 100644 --- a/astroid/brain/brain_namedtuple_enum.py +++ b/astroid/brain/brain_namedtuple_enum.py @@ -223,7 +223,9 @@ def infer_named_tuple( except StopIteration as e: raise InferenceError(node=node) from e try: - rename = next(call_site.infer_argument(func, "rename", context)).bool_value() + rename = next( + call_site.infer_argument(func, "rename", context or InferenceContext()) + ).bool_value() except (InferenceError, StopIteration): rename = False diff --git a/astroid/exceptions.py b/astroid/exceptions.py index 05d1b22a..1acb2288 100644 --- a/astroid/exceptions.py +++ b/astroid/exceptions.py @@ -249,7 +249,7 @@ class InferenceError(ResolveError): # pylint: disable=too-many-instance-attribu stmts: Sequence[InferenceResult] | None = None, frame: InferenceResult | None = None, call_site: arguments.CallSite | None = None, - func: nodes.FunctionDef | None = None, + func: InferenceResult | None = None, arg: str | None = None, positional_arguments: list | None = None, unpacked_args: list | None = None, |