summaryrefslogtreecommitdiff
path: root/astroid/interpreter/objectmodel.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-03-03 21:19:55 +0000
committerClaudiu Popa <pcmanticore@gmail.com>2016-03-03 21:19:55 +0000
commita315ef29ff51ff861cb5111d706bc17d6375f0de (patch)
treed3567dd277ece40ae2c378377d2b0afe6ebd75c8 /astroid/interpreter/objectmodel.py
parent9613be5921f777fc0a41269f869e20a4e7124834 (diff)
downloadastroid-git-a315ef29ff51ff861cb5111d706bc17d6375f0de.tar.gz
Exceptions have their own object model
Some of exceptions's attributes, such as .args and .message, can't be inferred correctly since they are descriptors that get transformed into the proper objects at runtime. This can cause issues with the static analysis, since they are inferred as different than what's expected. Now when we're creating instances of exceptions, we're inferring a special object that knows how to transform those runtime attributes into the proper objects via a custom object model. Closes #81
Diffstat (limited to 'astroid/interpreter/objectmodel.py')
-rw-r--r--astroid/interpreter/objectmodel.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/astroid/interpreter/objectmodel.py b/astroid/interpreter/objectmodel.py
index 7c32e6fc..af1205cd 100644
--- a/astroid/interpreter/objectmodel.py
+++ b/astroid/interpreter/objectmodel.py
@@ -41,6 +41,7 @@ mechanism.
import itertools
import pprint
import os
+import types
import six
@@ -518,3 +519,29 @@ class InstanceModel(ObjectModel):
@property
def py__dict__(self):
return _dunder_dict(self._instance, self._instance.instance_attrs)
+
+
+class ExceptionInstanceModel(InstanceModel):
+
+ @property
+ def pyargs(self):
+ message = node_classes.Const('')
+ args = node_classes.Tuple(parent=self._instance)
+ args.postinit((message, ))
+ return args
+
+ if six.PY3:
+ # It's available only on Python 3.
+
+ @property
+ def py__traceback__(self):
+ builtins = astroid.MANAGER.builtins()
+ traceback_type = builtins[types.TracebackType.__name__]
+ return traceback_type.instantiate_class()
+
+ if six.PY2:
+ # It's available only on Python 2.
+
+ @property
+ def pymessage(self):
+ return node_classes.Const('')