diff options
author | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-22 21:40:12 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2015-10-22 21:40:12 +0100 |
commit | 4272e1326efcbca5b26eecd4d8fd43bcc8cf93f2 (patch) | |
tree | 6d100f62fb11a360674f281ee801ec3252ee5fda /astroid/inference.py | |
parent | 6c250a70175892cdd6ad1e84d071197e1ba4e56b (diff) | |
download | astroid-4272e1326efcbca5b26eecd4d8fd43bcc8cf93f2.tar.gz |
Add support for indexing containers with instances which provides an __index__ returning-int method.
This patch moves _class_as_index to helpers, where it becames class_instance_as_index.
Also, it instantiates its own call context, which makes certain idioms with lambdas
to work.
Diffstat (limited to 'astroid/inference.py')
-rw-r--r-- | astroid/inference.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/astroid/inference.py b/astroid/inference.py index b1c81da..3253acb 100644 --- a/astroid/inference.py +++ b/astroid/inference.py @@ -252,6 +252,10 @@ def infer_subscript(self, context=None): step = _slice_value(index.step, context) if all(elem is not _SLICE_SENTINEL for elem in (lower, upper, step)): index_value = slice(lower, upper, step) + elif isinstance(index, bases.Instance): + index = helpers.class_instance_as_index(index) + if index: + index_value = index.value else: raise exceptions.InferenceError() |