mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-19 23:09:43 +08:00
fixed some array indexing
This commit is contained in:
@@ -307,16 +307,12 @@ class Evaluator(object):
|
|||||||
else:
|
else:
|
||||||
if isinstance(current, pr.NamePart):
|
if isinstance(current, pr.NamePart):
|
||||||
# This is the first global lookup.
|
# This is the first global lookup.
|
||||||
scopes = self.find_types(scope, current, position=position,
|
types = self.find_types(scope, current, position=position,
|
||||||
search_global=True)
|
search_global=True)
|
||||||
else:
|
else:
|
||||||
# for pr.Literal
|
# for pr.Literal
|
||||||
scopes = self.find_types(compiled.builtin, current.type_as_string())
|
types = [compiled.create(current.value)]
|
||||||
# Make instances of those number/string objects.
|
types = imports.strip_imports(self, types)
|
||||||
scopes = itertools.chain.from_iterable(
|
|
||||||
self.execute(s, (current.value,)) for s in scopes
|
|
||||||
)
|
|
||||||
types = imports.strip_imports(self, scopes)
|
|
||||||
|
|
||||||
return self.follow_path(path, types, scope, position=position)
|
return self.follow_path(path, types, scope, position=position)
|
||||||
|
|
||||||
@@ -412,7 +408,7 @@ class Evaluator(object):
|
|||||||
else:
|
else:
|
||||||
stmts = er.FunctionExecution(self, obj, params).get_return_types(evaluate_generator)
|
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)
|
return imports.strip_imports(self, stmts)
|
||||||
|
|
||||||
def goto(self, stmt, call_path=None):
|
def goto(self, stmt, call_path=None):
|
||||||
|
|||||||
@@ -68,7 +68,8 @@ class PyObject(Base):
|
|||||||
def execute(self, params):
|
def execute(self, params):
|
||||||
t = self.type()
|
t = self.type()
|
||||||
if t == 'class':
|
if t == 'class':
|
||||||
yield PyObject(self.obj, self.parent, True)
|
if not self.instantiated:
|
||||||
|
yield PyObject(self.obj, self.parent, True)
|
||||||
elif t == 'def':
|
elif t == 'def':
|
||||||
for name in self._parse_function_doc()[1].split():
|
for name in self._parse_function_doc()[1].split():
|
||||||
try:
|
try:
|
||||||
@@ -213,3 +214,7 @@ def _parse_function_doc(doc):
|
|||||||
|
|
||||||
builtin = PyObject(_builtins)
|
builtin = PyObject(_builtins)
|
||||||
magic_function_class = PyObject(type(load_module), parent=builtin)
|
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 common
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi import settings
|
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.parser import representation as pr
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate import helpers
|
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,
|
# This is indexing only one element, with a fixed index number,
|
||||||
# otherwise it just ignores the index (e.g. [1+1]).
|
# otherwise it just ignores the index (e.g. [1+1]).
|
||||||
index = index_possibilities[0]
|
index = index_possibilities[0]
|
||||||
|
if isinstance(index, compiled.PyObject) \
|
||||||
from jedi.evaluate.representation import Instance
|
and isinstance(index.obj, (int, str, unicode)):
|
||||||
if isinstance(index, Instance) \
|
with common.ignored(KeyError, IndexError, TypeError):
|
||||||
and str(index.name) in ['int', 'str'] \
|
return self.get_exact_index_types(index.obj)
|
||||||
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])
|
|
||||||
|
|
||||||
result = list(self._follow_values(self._array.values))
|
result = list(self._follow_values(self._array.values))
|
||||||
result += check_array_additions(self._evaluator, self)
|
result += check_array_additions(self._evaluator, self)
|
||||||
|
|||||||
@@ -1239,9 +1239,6 @@ class Literal(StatementElement):
|
|||||||
def get_code(self):
|
def get_code(self):
|
||||||
return self.literal + super(Literal, self).get_code()
|
return self.literal + super(Literal, self).get_code()
|
||||||
|
|
||||||
def type_as_string(self):
|
|
||||||
return type(self.value).__name__
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if is_py3k:
|
if is_py3k:
|
||||||
s = self.literal
|
s = self.literal
|
||||||
|
|||||||
Reference in New Issue
Block a user