mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 15:55:23 +08:00
fixed some array indexing
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user