diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2016-03-06 21:44:45 +0000 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2016-06-04 10:38:26 +0100 |
commit | 0d65b5bdc970367415dd68bdaae912cef999d16f (patch) | |
tree | 29fb5f6ce6436d3a858958a757d94ade7b4a5a53 /astroid/objects.py | |
parent | e1b66de78193b910707b665f1623d67dde86ac2f (diff) | |
download | astroid-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.py | 32 |
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) |