1
0
forked from VimPlug/jedi

Catch an error with illegal class instances, fixes #1491

This commit is contained in:
Dave Halter
2020-02-03 22:27:22 +01:00
parent 2c62166ff6
commit eb88c483fb
2 changed files with 13 additions and 1 deletions

View File

@@ -570,4 +570,6 @@ def _is_class_instance(obj):
except AttributeError: except AttributeError:
return False return False
else: else:
return cls != type and not issubclass(cls, NOT_CLASS_TYPES) # The isinstance check for cls is just there so issubclass doesn't
# raise an exception.
return cls != type and isinstance(cls, type) and not issubclass(cls, NOT_CLASS_TYPES)

View File

@@ -530,6 +530,16 @@ def test__wrapped__():
assert c.line == syslogs_to_df.__wrapped__.__code__.co_firstlineno + 1 assert c.line == syslogs_to_df.__wrapped__.__code__.co_firstlineno + 1
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
def test_illegal_class_instance():
class X:
__class__ = 1
X.__name__ = 'asdf'
d, = jedi.Interpreter('foo', [{'foo': X()}]).infer()
v, = d._name.infer()
assert not v.is_instance()
@pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL") @pytest.mark.skipif(sys.version_info[0] == 2, reason="Ignore Python 2, because EOL")
@pytest.mark.parametrize('module_name', ['sys', 'time', 'unittest.mock']) @pytest.mark.parametrize('module_name', ['sys', 'time', 'unittest.mock'])
def test_core_module_completes(module_name): def test_core_module_completes(module_name):