From 9056dc1b9b82f9c7a4a1848af32040aba6a8ade1 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 9 Jan 2014 19:55:00 +0100 Subject: [PATCH] fixed some array indexing --- jedi/evaluate/__init__.py | 14 +++++--------- jedi/evaluate/compiled.py | 7 ++++++- jedi/evaluate/iterable.py | 16 +++++----------- jedi/parser/representation.py | 3 --- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/jedi/evaluate/__init__.py b/jedi/evaluate/__init__.py index fd764f77..f3ccbf16 100644 --- a/jedi/evaluate/__init__.py +++ b/jedi/evaluate/__init__.py @@ -307,16 +307,12 @@ class Evaluator(object): else: if isinstance(current, pr.NamePart): # This is the first global lookup. - scopes = self.find_types(scope, current, position=position, - search_global=True) + types = self.find_types(scope, current, position=position, + search_global=True) else: # for pr.Literal - scopes = self.find_types(compiled.builtin, current.type_as_string()) - # Make instances of those number/string objects. - scopes = itertools.chain.from_iterable( - self.execute(s, (current.value,)) for s in scopes - ) - types = imports.strip_imports(self, scopes) + types = [compiled.create(current.value)] + types = imports.strip_imports(self, types) return self.follow_path(path, types, scope, position=position) @@ -412,7 +408,7 @@ class Evaluator(object): else: stmts = er.FunctionExecution(self, obj, params).get_return_types(evaluate_generator) - debug.dbg('execute: %s in %s' % (stmts, self)) + debug.dbg('execute: %s in %s' % (stmts, obj)) return imports.strip_imports(self, stmts) def goto(self, stmt, call_path=None): diff --git a/jedi/evaluate/compiled.py b/jedi/evaluate/compiled.py index 78e5afd9..d2d54e5a 100644 --- a/jedi/evaluate/compiled.py +++ b/jedi/evaluate/compiled.py @@ -68,7 +68,8 @@ class PyObject(Base): def execute(self, params): t = self.type() if t == 'class': - yield PyObject(self.obj, self.parent, True) + if not self.instantiated: + yield PyObject(self.obj, self.parent, True) elif t == 'def': for name in self._parse_function_doc()[1].split(): try: @@ -213,3 +214,7 @@ def _parse_function_doc(doc): builtin = PyObject(_builtins) magic_function_class = PyObject(type(load_module), parent=builtin) + + +def create(obj): + return PyObject(obj, builtin) diff --git a/jedi/evaluate/iterable.py b/jedi/evaluate/iterable.py index 4fab6c1d..985b08b5 100644 --- a/jedi/evaluate/iterable.py +++ b/jedi/evaluate/iterable.py @@ -3,7 +3,7 @@ import itertools from jedi import common from jedi import debug from jedi import settings -from jedi._compatibility import use_metaclass, is_py3k +from jedi._compatibility import use_metaclass, is_py3k, unicode from jedi.parser import representation as pr from jedi.evaluate import compiled from jedi.evaluate import helpers @@ -78,16 +78,10 @@ class Array(use_metaclass(CachedMetaClass, pr.Base)): # This is indexing only one element, with a fixed index number, # otherwise it just ignores the index (e.g. [1+1]). index = index_possibilities[0] - - from jedi.evaluate.representation import Instance - if isinstance(index, Instance) \ - and str(index.name) in ['int', 'str'] \ - and len(index.var_args) == 1: - # TODO this is just very hackish and a lot of use cases are - # being ignored - with common.ignored(KeyError, IndexError, - UnboundLocalError, TypeError): - return self.get_exact_index_types(index.var_args[0]) + if isinstance(index, compiled.PyObject) \ + and isinstance(index.obj, (int, str, unicode)): + with common.ignored(KeyError, IndexError, TypeError): + return self.get_exact_index_types(index.obj) result = list(self._follow_values(self._array.values)) result += check_array_additions(self._evaluator, self) diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index b9feea5e..10e9882b 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -1239,9 +1239,6 @@ class Literal(StatementElement): def get_code(self): return self.literal + super(Literal, self).get_code() - def type_as_string(self): - return type(self.value).__name__ - def __repr__(self): if is_py3k: s = self.literal