Skip to content

Commit

Permalink
Correctly instantiate exception instances when inferring their attrib…
Browse files Browse the repository at this point in the history
…utes with objectmodel

Close pylint-dev/pylint#2776
  • Loading branch information
PCManticore committed Feb 28, 2019
1 parent 20340ac commit d888495
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion astroid/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def special_attributes(self):
instance = objectmodel.BUILTIN_EXCEPTIONS.get(
qname, objectmodel.ExceptionInstanceModel
)
return instance()
return instance()(self)


class DictInstance(bases.Instance):
Expand Down
14 changes: 14 additions & 0 deletions astroid/tests/unittest_object_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,20 @@ def test_import_error(self):
assert isinstance(inferred, astroid.Const)
assert inferred.value == ""

def test_exception_instance_correctly_instantiated(self):
ast_node = builder.extract_node(
"""
try:
raise ImportError("a")
except ImportError as err:
err #@
"""
)
inferred = next(ast_node.infer())
assert isinstance(inferred, astroid.Instance)
cls = next(inferred.igetattr("__class__"))
assert isinstance(cls, astroid.ClassDef)


class DictObjectModelTest(unittest.TestCase):
def test__class__(self):
Expand Down

0 comments on commit d888495

Please sign in to comment.