Skip to content

Commit

Permalink
Allow passing UninferableBase to safe_infer
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed May 1, 2023
1 parent 4fe752e commit faea711
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion astroid/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ def object_issubclass(node, class_or_seq, context: InferenceContext | None = Non


def safe_infer(
node: nodes.NodeNG | bases.Proxy, context: InferenceContext | None = None
node: nodes.NodeNG | bases.Proxy | util.UninferableBase,
context: InferenceContext | None = None,
) -> InferenceResult | None:
"""Return the inferred value for the given node.
Return None if inference failed or if there is some ambiguity (more than
one node has been inferred).
"""
if isinstance(node, util.UninferableBase):
return node
try:
inferit = node.infer(context=context)
value = next(inferit)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,8 @@ class A(type): #@
builtin_type = self._extract("type")
self.assertTrue(helpers.is_supertype(builtin_type, cls_a))
self.assertTrue(helpers.is_subtype(cls_a, builtin_type))


def test_uninferable_for_safe_infer() -> None:
uninfer = util.Uninferable
assert helpers.safe_infer(util.Uninferable) == uninfer

0 comments on commit faea711

Please sign in to comment.