Skip to content

Commit

Permalink
Fix crash while obtaining object_type() of an Unknown node (#1547)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed May 7, 2022
1 parent 5cf7786 commit 95403ff
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Expand Up @@ -28,7 +28,9 @@ What's New in astroid 2.11.5?
=============================
Release date: TBA

* Fix crash while obtaining ``object_type()`` of an ``Unknown`` node.

Refs PyCQA/pylint#6539


What's New in astroid 2.11.4?
Expand Down
2 changes: 2 additions & 0 deletions astroid/helpers.py
Expand Up @@ -55,6 +55,8 @@ def _object_type(node, context=None):
yield _function_type(inferred, builtins)
elif isinstance(inferred, scoped_nodes.Module):
yield _build_proxy_class("module", builtins)
elif isinstance(inferred, nodes.Unknown):
raise InferenceError
else:
yield inferred._proxied

Expand Down
8 changes: 8 additions & 0 deletions tests/unittest_helpers.py
Expand Up @@ -5,7 +5,10 @@
import builtins
import unittest

import pytest

from astroid import builder, helpers, manager, nodes, raw_building, util
from astroid.const import IS_PYPY
from astroid.exceptions import _NonDeducibleTypeHierarchy
from astroid.nodes.scoped_nodes import ClassDef

Expand Down Expand Up @@ -144,6 +147,11 @@ def test_inference_errors(self) -> None:
)
self.assertEqual(helpers.object_type(node), util.Uninferable)

@pytest.mark.skipif(IS_PYPY, reason="__code__ will not be Unknown on PyPy")
def test_inference_errors_2(self) -> None:
node = builder.extract_node("type(float.__new__.__code__)")
self.assertIs(helpers.object_type(node), util.Uninferable)

def test_object_type_too_many_types(self) -> None:
node = builder.extract_node(
"""
Expand Down

0 comments on commit 95403ff

Please sign in to comment.