|
6 | 6 |
|
7 | 7 | from __future__ import annotations
|
8 | 8 |
|
| 9 | +import warnings |
9 | 10 | from collections.abc import Generator
|
10 | 11 |
|
11 | 12 | from astroid import bases, manager, nodes, objects, raw_building, util
|
|
19 | 20 | )
|
20 | 21 | from astroid.nodes import scoped_nodes
|
21 | 22 | from astroid.typing import InferenceResult
|
| 23 | +from astroid.util import safe_infer as real_safe_infer |
22 | 24 |
|
23 |
| -# Don't remove the following safe_infer import without a deprecation notice. |
24 |
| -# safe_infer was moved to util in #2232, but can be accessed here via this. |
25 |
| -from astroid.util import safe_infer |
| 25 | + |
| 26 | +def safe_infer( |
| 27 | + node: nodes.NodeNG | bases.Proxy | util.UninferableBase, |
| 28 | + context: InferenceContext | None = None, |
| 29 | +) -> InferenceResult | None: |
| 30 | + # When removing, also remove the real_safe_infer alias |
| 31 | + warnings.warn( |
| 32 | + "Import safe_infer from astroid.util; this shim in astroid.helpers will be removed.", |
| 33 | + DeprecationWarning, |
| 34 | + stacklevel=2, |
| 35 | + ) |
| 36 | + return real_safe_infer(node, context=context) |
26 | 37 |
|
27 | 38 |
|
28 | 39 | def _build_proxy_class(cls_name: str, builtins: nodes.Module) -> nodes.ClassDef:
|
@@ -166,7 +177,7 @@ def has_known_bases(klass, context: InferenceContext | None = None) -> bool:
|
166 | 177 | except AttributeError:
|
167 | 178 | pass
|
168 | 179 | for base in klass.bases:
|
169 |
| - result = safe_infer(base, context=context) |
| 180 | + result = real_safe_infer(base, context=context) |
170 | 181 | # TODO: check for A->B->A->B pattern in class structure too?
|
171 | 182 | if (
|
172 | 183 | not isinstance(result, scoped_nodes.ClassDef)
|
@@ -241,7 +252,7 @@ def object_len(node, context: InferenceContext | None = None):
|
241 | 252 | # pylint: disable=import-outside-toplevel; circular import
|
242 | 253 | from astroid.objects import FrozenSet
|
243 | 254 |
|
244 |
| - inferred_node = safe_infer(node, context=context) |
| 255 | + inferred_node = real_safe_infer(node, context=context) |
245 | 256 |
|
246 | 257 | # prevent self referential length calls from causing a recursion error
|
247 | 258 | # see https://github.com/pylint-dev/astroid/issues/777
|
|
0 commit comments