diff --git a/jedi/evaluate/base_context.py b/jedi/evaluate/base_context.py index e2e0a8e8..7559a6ca 100644 --- a/jedi/evaluate/base_context.py +++ b/jedi/evaluate/base_context.py @@ -93,7 +93,7 @@ class Context(BaseContext): except ValueError: pass - if type(index) not in (float, int, str, unicode, slice): + if type(index) not in (float, int, str, unicode, slice, bytes): # If the index is not clearly defined, we have to get all the # possiblities. if isinstance(self, AbstractIterable) and self.array_type == 'dict': diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index 65f7cb09..ccdf5db3 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -22,6 +22,7 @@ It is important to note that: """ from jedi import debug from jedi import settings +from jedi._compatibility import force_unicode from jedi.evaluate import compiled from jedi.evaluate import analysis from jedi.evaluate import recursion @@ -298,10 +299,11 @@ class SequenceLiteralContext(ArrayMixin, AbstractIterable): def py__getitem__(self, index): """Here the index is an int/str. Raises IndexError/KeyError.""" if self.array_type == 'dict': + compiled_obj_index = compiled.create_simple_object(self.evaluator, index) for key, value in self._items(): for k in self._defining_context.eval_node(key): if isinstance(k, compiled.CompiledObject) \ - and index == k.get_safe_value(default=None): + and k.execute_operation(compiled_obj_index, '==').get_safe_value(): return self._defining_context.eval_node(value) raise KeyError('No key found in dictionary %s.' % self) diff --git a/jedi/evaluate/helpers.py b/jedi/evaluate/helpers.py index 84c8a668..25c28cb3 100644 --- a/jedi/evaluate/helpers.py +++ b/jedi/evaluate/helpers.py @@ -190,7 +190,11 @@ def is_compiled(context): def is_string(context): - return is_compiled(context) and isinstance(context.get_safe_value(default=None), (str, unicode)) + if context.evaluator.environment.version_info.major == 2: + str_classes = (str, unicode, bytes) + else: + str_classes = (str,) + return is_compiled(context) and isinstance(context.get_safe_value(default=None), str_classes) def is_literal(context):