1
0
forked from VimPlug/jedi

NamePart doesn't have an __eq__ method anymore

This commit is contained in:
Dave Halter
2014-04-18 14:36:10 +02:00
parent c2bdda339b
commit 240b0c9581
11 changed files with 46 additions and 52 deletions

View File

@@ -334,7 +334,7 @@ class Evaluator(object):
def goto(self, stmt, call_path):
scope = stmt.get_parent_until(pr.IsScope)
pos = stmt.start_pos
call_path, search = call_path[:-1], call_path[-1]
call_path, search_name_part = call_path[:-1], call_path[-1]
if call_path:
scopes = self.eval_call_path(iter(call_path), scope, pos)
@@ -346,9 +346,9 @@ class Evaluator(object):
search_global = True
follow_res = []
for s in scopes:
follow_res += self.find_types(s, search, pos,
follow_res += self.find_types(s, search_name_part, pos,
search_global=search_global, is_goto=True)
return follow_res, search
return follow_res, search_name_part
def filter_private_variable(scope, call_scope, var_name):

View File

@@ -17,6 +17,7 @@ It works as follows:
- execute these calls and check the input. This work with a ``ParamListener``.
"""
from jedi._compatibility import unicode
from jedi.parser import representation as pr
from jedi import settings
from jedi.evaluate import helpers
@@ -86,9 +87,11 @@ def search_params(evaluator, param):
# Need to take right index, because there could be a
# func usage before.
i = listRightIndex(call_path, func_name)
call_path_simple = [unicode(d) if isinstance(d, pr.NamePart)
else d for d in call_path]
i = listRightIndex(call_path_simple, func_name)
first, last = call_path[:i], call_path[i + 1:]
if not last and not call_path.index(func_name) != i:
if not last and not call_path_simple.index(func_name) != i:
continue
scopes = [scope]
if first:
@@ -119,10 +122,10 @@ def search_params(evaluator, param):
func = param.get_parent_until(pr.Function)
current_module = param.get_parent_until()
func_name = str(func.name)
func_name = unicode(func.name)
compare = func
if func_name == '__init__' and isinstance(func.parent, pr.Class):
func_name = str(func.parent.name)
func_name = unicode(func.parent.name)
compare = func.parent
# get the param name

View File

@@ -69,7 +69,7 @@ class NameFinder(object):
# reference.
name_list = sorted(name_list, key=lambda n: n.start_pos, reverse=True)
for name in name_list:
if self.name_str != name.get_code():
if unicode(self.name_str) != name.get_code():
continue
parpar = name.parent.parent
@@ -297,7 +297,7 @@ class NameFinder(object):
return result
def check_flow_information(evaluator, flow, search_name, pos):
def check_flow_information(evaluator, flow, search_name_part, pos):
""" Try to find out the type of a variable just with the information that
is given by the flows: e.g. It is also responsible for assert checks.::
@@ -314,17 +314,17 @@ def check_flow_information(evaluator, flow, search_name, pos):
for ass in reversed(flow.asserts):
if pos is None or ass.start_pos > pos:
continue
result = _check_isinstance_type(evaluator, ass, search_name)
result = _check_isinstance_type(evaluator, ass, search_name_part)
if result:
break
if isinstance(flow, pr.Flow) and not result:
if flow.command in ['if', 'while'] and len(flow.inputs) == 1:
result = _check_isinstance_type(evaluator, flow.inputs[0], search_name)
result = _check_isinstance_type(evaluator, flow.inputs[0], search_name_part)
return result
def _check_isinstance_type(evaluator, stmt, search_name):
def _check_isinstance_type(evaluator, stmt, search_name_part):
try:
expression_list = stmt.expression_list()
# this might be removed if we analyze and, etc
@@ -342,7 +342,7 @@ def _check_isinstance_type(evaluator, stmt, search_name):
assert isinstance(obj[0], pr.Call)
# names fit?
assert str(obj[0].name) == search_name
assert unicode(obj[0].name) == unicode(search_name_part)
assert isinstance(classes[0], pr.StatementElement) # can be type or tuple
except AssertionError:
return []
@@ -530,7 +530,7 @@ def find_assignments(lhs, results, seek_name):
"""
if isinstance(lhs, pr.Array):
return _assign_tuples(lhs, results, seek_name)
elif lhs.name.names[-1] == seek_name:
elif unicode(lhs.name.names[-1]) == unicode(seek_name):
return results
else:
return []

View File

@@ -148,7 +148,8 @@ def scan_statement_for_calls(stmt, search_name, assignment_details=False):
s_new = c
while s_new is not None:
n = s_new.name
if isinstance(n, pr.Name) and search_name in n.names:
if isinstance(n, pr.Name) \
and search_name in [str(x) for x in n.names]:
result.append(c)
if s_new.execution is not None:

View File

@@ -276,8 +276,10 @@ def _check_array_additions(evaluator, compare_array, module, is_list):
result = []
for c in calls:
call_path = list(c.generate_call_path())
separate_index = call_path.index(add_name)
if add_name == call_path[-1] or separate_index == 0:
call_path_simple = [unicode(n) if isinstance(n, pr.NamePart) else n
for n in call_path]
separate_index = call_path_simple.index(add_name)
if add_name == call_path_simple[-1] or separate_index == 0:
# this means that there is no execution -> [].append
# or the keyword is at the start -> append()
continue

View File

@@ -113,7 +113,7 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
# Only names with the selfname are being added.
# It is also important, that they have a len() of 2,
# because otherwise, they are just something else
if n.names[0] == self_name and len(n.names) == 2:
if unicode(n.names[0]) == self_name and len(n.names) == 2:
add_self_dot_name(n)
if not isinstance(self.base, compiled.CompiledObject):
@@ -278,7 +278,7 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
for i in iterable:
# Only the last name is important, because these names have a
# maximal length of 2, with the first one being `self`.
if i.names[-1] == name.names[-1]:
if unicode(i.names[-1]) == unicode(name.names[-1]):
return True
return False

View File

@@ -1,7 +1,7 @@
import os
import sys
from jedi._compatibility import exec_function
from jedi._compatibility import exec_function, unicode
from jedi.parser import representation as pr
from jedi import debug
from jedi import common
@@ -59,9 +59,9 @@ def sys_path_with_modifications(module):
n = call.name
if not isinstance(n, pr.Name) or len(n.names) != 3:
continue
if n.names[:2] != ('sys', 'path'):
if [unicode(x) for x in n.names[:2]] != ['sys', 'path']:
continue
array_cmd = n.names[2]
array_cmd = unicode(n.names[2])
if call.execution is None:
continue
exe = call.execution