diff options
author | Daniƫl van Noord <13665637+DanielNoord@users.noreply.github.com> | 2023-04-05 07:38:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-05 07:38:09 +0200 |
commit | 569b63706ea5ab7efab7ffe2ef91e6772c5e38ec (patch) | |
tree | 4239de4f5dd5f94234786b0cb5ec6dbda028deda /astroid | |
parent | fc278f79f2981066c79213815efe1a25550360db (diff) | |
download | astroid-git-569b63706ea5ab7efab7ffe2ef91e6772c5e38ec.tar.gz |
Type ``igetattr`` (#2101)
Diffstat (limited to 'astroid')
-rw-r--r-- | astroid/bases.py | 10 | ||||
-rw-r--r-- | astroid/nodes/node_classes.py | 8 | ||||
-rw-r--r-- | astroid/nodes/scoped_nodes/scoped_nodes.py | 10 | ||||
-rw-r--r-- | astroid/objects.py | 5 |
4 files changed, 20 insertions, 13 deletions
diff --git a/astroid/bases.py b/astroid/bases.py index 5a6c46d0..3e8a5feb 100644 --- a/astroid/bases.py +++ b/astroid/bases.py @@ -10,7 +10,7 @@ from __future__ import annotations import collections import collections.abc import sys -from collections.abc import Sequence +from collections.abc import Iterator, Sequence from typing import TYPE_CHECKING, Any, ClassVar from astroid import nodes @@ -255,7 +255,9 @@ class BaseInstance(Proxy): pass return values - def igetattr(self, name, context: InferenceContext | None = None): + def igetattr( + self, name: str, context: InferenceContext | None = None + ) -> Iterator[InferenceResult]: """Inferred getattr.""" if not context: context = InferenceContext() @@ -429,7 +431,9 @@ class UnboundMethod(Proxy): return [self.special_attributes.lookup(name)] return self._proxied.getattr(name, context) - def igetattr(self, name, context: InferenceContext | None = None): + def igetattr( + self, name: str, context: InferenceContext | None = None + ) -> Iterator[InferenceResult]: if name in self.special_attributes: return iter((self.special_attributes.lookup(name),)) return self._proxied.igetattr(name, context) diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index 8092abcf..2b24d8ef 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -11,7 +11,7 @@ import itertools import sys import typing import warnings -from collections.abc import Generator, Iterable, Mapping +from collections.abc import Generator, Iterable, Iterator, Mapping from functools import lru_cache from typing import TYPE_CHECKING, Any, Callable, ClassVar, Optional, TypeVar, Union @@ -3237,14 +3237,14 @@ class Slice(NodeNG): """ return "builtins.slice" - def igetattr(self, attrname, context: InferenceContext | None = None): + def igetattr( + self, attrname: str, context: InferenceContext | None = None + ) -> Iterator[SuccessfulInferenceResult]: """Infer the possible values of the given attribute on the slice. :param attrname: The name of the attribute to infer. - :type attrname: str :returns: The inferred possible values. - :rtype: iterable(NodeNG) """ if attrname == "start": yield self._wrap_attribute(self.lower) diff --git a/astroid/nodes/scoped_nodes/scoped_nodes.py b/astroid/nodes/scoped_nodes/scoped_nodes.py index 49ca3eb1..c7523772 100644 --- a/astroid/nodes/scoped_nodes/scoped_nodes.py +++ b/astroid/nodes/scoped_nodes/scoped_nodes.py @@ -416,14 +416,14 @@ class Module(LocalsDictNodeNG): return result raise AttributeInferenceError(target=self, attribute=name, context=context) - def igetattr(self, name, context: InferenceContext | None = None): + def igetattr( + self, name: str, context: InferenceContext | None = None + ) -> Iterator[InferenceResult]: """Infer the possible values of the given variable. :param name: The name of the variable to infer. - :type name: str :returns: The inferred possible values. - :rtype: iterable(NodeNG) or None """ # set lookup name since this is necessary to infer on import nodes for # instance @@ -1560,7 +1560,9 @@ class FunctionDef(_base_nodes.MultiLineBlockNode, _base_nodes.Statement, Lambda) """ return self.fromlineno, self.tolineno - def igetattr(self, name, context: InferenceContext | None = None): + def igetattr( + self, name: str, context: InferenceContext | None = None + ) -> Iterator[InferenceResult]: """Inferred getattr, which returns an iterator of inferred statements.""" try: return bases._infer_stmts(self.getattr(name, context), context, frame=self) diff --git a/astroid/objects.py b/astroid/objects.py index 6cc4e9a7..8d1a241b 100644 --- a/astroid/objects.py +++ b/astroid/objects.py @@ -14,7 +14,7 @@ leads to an inferred FrozenSet: from __future__ import annotations import sys -from collections.abc import Generator +from collections.abc import Generator, Iterator from typing import Any, TypeVar from astroid import bases, decorators, util @@ -27,6 +27,7 @@ from astroid.exceptions import ( ) from astroid.manager import AstroidManager from astroid.nodes import node_classes, scoped_nodes +from astroid.typing import InferenceResult objectmodel = util.lazy_import("interpreter.objectmodel") @@ -140,7 +141,7 @@ class Super(node_classes.NodeNG): def igetattr( # noqa: C901 self, name: str, context: InferenceContext | None = None - ): + ) -> Iterator[InferenceResult]: """Retrieve the inferred values of the given attribute name.""" # '__class__' is a special attribute that should be taken directly # from the special attributes dict |