summaryrefslogtreecommitdiff
path: root/astroid/objects.py
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-03-06 21:44:45 +0000
committerClaudiu Popa <pcmanticore@gmail.com>2016-06-04 10:38:26 +0100
commit0d65b5bdc970367415dd68bdaae912cef999d16f (patch)
tree29fb5f6ce6436d3a858958a757d94ade7b4a5a53 /astroid/objects.py
parente1b66de78193b910707b665f1623d67dde86ac2f (diff)
downloadastroid-git-0d65b5bdc970367415dd68bdaae912cef999d16f.tar.gz
dict.values, dict.keys and dict.items are properly inferred
Diffstat (limited to 'astroid/objects.py')
-rw-r--r--astroid/objects.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/astroid/objects.py b/astroid/objects.py
index 83074664..ce2c80a5 100644
--- a/astroid/objects.py
+++ b/astroid/objects.py
@@ -180,3 +180,35 @@ class ExceptionInstance(bases.Instance):
"""
special_attributes = util.lazy_descriptor(lambda: objectmodel.ExceptionInstanceModel())
+
+
+class DictInstance(bases.Instance):
+ """Special kind of instances for dictionaries
+
+ This instance knows the underlying object model of the dictionaries, which means
+ that methods such as .values or .items can be properly inferred.
+ """
+
+ special_attributes = util.lazy_descriptor(lambda: objectmodel.DictModel())
+
+
+# Custom objects tailored for dictionaries, which are used to
+# disambiguate between the types of Python 2 dict's method returns
+# and Python 3 (where they return set like objects).
+class DictItems(bases.Proxy):
+ __str__ = node_classes.NodeNG.__str__
+ __repr__ = node_classes.NodeNG.__repr__
+
+
+class DictKeys(bases.Proxy):
+ __str__ = node_classes.NodeNG.__str__
+ __repr__ = node_classes.NodeNG.__repr__
+
+
+class DictValues(bases.Proxy):
+ __str__ = node_classes.NodeNG.__str__
+ __repr__ = node_classes.NodeNG.__repr__
+
+# TODO: Hack to solve the circular import problem between node_classes and objects
+# This is not needed in 2.0, which has a cleaner design overall
+node_classes.Dict.__bases__ = (node_classes.NodeNG, DictInstance)