def py__simple_getitem__(self, index): with reraise_getitem_errors(IndexError, KeyError, TypeError): access = self.access_handle.py__simple_getitem__(index) if access is None: return NO_CONTEXTS return ContextSet([create_from_access_path(self.evaluator, access)])
def py__simple_getitem__(self, index): if isinstance(index, slice): return ContextSet([self]) with reraise_getitem_errors(IndexError, TypeError): lazy_context = self._lazy_context_list[index] return lazy_context.infer()
def py__simple_getitem__(self, index): if isinstance(index, slice): return ContextSet([self]) all_types = list(self.py__iter__()) with reraise_getitem_errors(IndexError, TypeError): lazy_context = all_types[index] return lazy_context.infer()
def py__simple_getitem__(self, index): if is_py3 and self.evaluator.environment.version_info.major == 2: # In Python 2 bytes and unicode compare. if isinstance(index, bytes): index_unicode = force_unicode(index) try: return self._dct[index_unicode].infer() except KeyError: pass elif isinstance(index, str): index_bytes = index.encode('utf-8') try: return self._dct[index_bytes].infer() except KeyError: pass with reraise_getitem_errors(KeyError, TypeError): lazy_context = self._dct[index] return lazy_context.infer()
def py__simple_getitem__(self, index): """Here the index is an int/str. Raises IndexError/KeyError.""" if self.array_type == u'dict': compiled_obj_index = compiled.create_simple_object(self.evaluator, index) for key, value in self.get_tree_entries(): for k in self._defining_context.eval_node(key): try: method = k.execute_operation except AttributeError: pass else: if method(compiled_obj_index, u'==').get_safe_value(): return self._defining_context.eval_node(value) raise SimpleGetItemNotFound('No key found in dictionary %s.' % self) if isinstance(index, slice): return ContextSet([self]) else: with reraise_getitem_errors(TypeError, KeyError, IndexError): node = self.get_tree_entries()[index] return self._defining_context.eval_node(node)
def py__simple_getitem__(self, index): with reraise_getitem_errors(IndexError, TypeError): lazy_context = self._lazy_context_list[index] return lazy_context.infer()