Skip to content

Commit fb553fd

Browse files
jacobtylerwallsPierre-Sassoulas
authored andcommitted
Fix crash while obtaining object_type() of an Unknown node (#1547)
1 parent 2d83696 commit fb553fd

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ What's New in astroid 2.11.5?
1717
=============================
1818
Release date: TBA
1919

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

22+
Refs PyCQA/pylint#6539
2123

2224
What's New in astroid 2.11.4?
2325
=============================

astroid/helpers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def _object_type(node, context=None):
5555
yield _function_type(inferred, builtins)
5656
elif isinstance(inferred, scoped_nodes.Module):
5757
yield _build_proxy_class("module", builtins)
58+
elif isinstance(inferred, nodes.Unknown):
59+
raise InferenceError
5860
else:
5961
yield inferred._proxied
6062

tests/unittest_helpers.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
import builtins
66
import unittest
77

8+
import pytest
9+
810
from astroid import builder, helpers, manager, nodes, raw_building, util
11+
from astroid.const import IS_PYPY
912
from astroid.exceptions import _NonDeducibleTypeHierarchy
1013
from astroid.nodes.scoped_nodes import ClassDef
1114

@@ -144,6 +147,11 @@ def test_inference_errors(self) -> None:
144147
)
145148
self.assertEqual(helpers.object_type(node), util.Uninferable)
146149

150+
@pytest.mark.skipif(IS_PYPY, reason="__code__ will not be Unknown on PyPy")
151+
def test_inference_errors_2(self) -> None:
152+
node = builder.extract_node("type(float.__new__.__code__)")
153+
self.assertIs(helpers.object_type(node), util.Uninferable)
154+
147155
def test_object_type_too_many_types(self) -> None:
148156
node = builder.extract_node(
149157
"""

0 commit comments

Comments
 (0)