Skip to content

Commit

Permalink
[safe_infer] Catch astroid.AttributeInferenceError in safe_infer
Browse files Browse the repository at this point in the history
Safe infer was not really safe, see pylint-dev/pylint#4692
  • Loading branch information
Pierre-Sassoulas committed Jul 10, 2021
1 parent eb41df3 commit e432bd2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions astroid/helpers.py
Expand Up @@ -15,7 +15,7 @@
"""
Various helper utilities.
"""

from typing import TYPE_CHECKING, Optional

from astroid import bases
from astroid import context as contextmod
Expand All @@ -29,6 +29,9 @@
_NonDeducibleTypeHierarchy,
)

if TYPE_CHECKING:
from astroid.nodes import NodeNG


def _build_proxy_class(cls_name, builtins):
proxy = raw_building.build_class(cls_name)
Expand Down Expand Up @@ -147,7 +150,7 @@ def object_issubclass(node, class_or_seq, context=None):
return _object_type_is_subclass(node, class_or_seq, context=context)


def safe_infer(node, context=None):
def safe_infer(node: "NodeNG", context=None) -> Optional["NodeNG"]:
"""Return the inferred value for the given node.
Return None if inference failed or if there is some ambiguity (more than
Expand All @@ -156,7 +159,7 @@ def safe_infer(node, context=None):
try:
inferit = node.infer(context=context)
value = next(inferit)
except (InferenceError, StopIteration):
except (InferenceError, StopIteration, AttributeInferenceError):
return None
try:
next(inferit)
Expand Down

0 comments on commit e432bd2

Please sign in to comment.