Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash while obtaining object_type() of an Unknown node #1547

Merged
merged 2 commits into from May 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved

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