Do more comparisons in the subprocess

This commit is contained in:
Dave Halter
2017-12-26 13:38:47 +01:00
parent ab42e856fb
commit c43009d5dc
3 changed files with 9 additions and 3 deletions

View File

@@ -93,7 +93,7 @@ class Context(BaseContext):
except ValueError: except ValueError:
pass 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 # If the index is not clearly defined, we have to get all the
# possiblities. # possiblities.
if isinstance(self, AbstractIterable) and self.array_type == 'dict': if isinstance(self, AbstractIterable) and self.array_type == 'dict':

View File

@@ -22,6 +22,7 @@ It is important to note that:
""" """
from jedi import debug from jedi import debug
from jedi import settings from jedi import settings
from jedi._compatibility import force_unicode
from jedi.evaluate import compiled from jedi.evaluate import compiled
from jedi.evaluate import analysis from jedi.evaluate import analysis
from jedi.evaluate import recursion from jedi.evaluate import recursion
@@ -298,10 +299,11 @@ class SequenceLiteralContext(ArrayMixin, AbstractIterable):
def py__getitem__(self, index): def py__getitem__(self, index):
"""Here the index is an int/str. Raises IndexError/KeyError.""" """Here the index is an int/str. Raises IndexError/KeyError."""
if self.array_type == 'dict': if self.array_type == 'dict':
compiled_obj_index = compiled.create_simple_object(self.evaluator, index)
for key, value in self._items(): for key, value in self._items():
for k in self._defining_context.eval_node(key): for k in self._defining_context.eval_node(key):
if isinstance(k, compiled.CompiledObject) \ 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) return self._defining_context.eval_node(value)
raise KeyError('No key found in dictionary %s.' % self) raise KeyError('No key found in dictionary %s.' % self)

View File

@@ -190,7 +190,11 @@ def is_compiled(context):
def is_string(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): def is_literal(context):