1
0
forked from VimPlug/jedi

Remove NamePart from existance and rename it to Name.

This commit is contained in:
Dave Halter
2014-09-26 16:29:53 +02:00
parent 522c9eda90
commit 03e01631cc
14 changed files with 36 additions and 37 deletions

View File

@@ -1,7 +1,6 @@
import pydoc
import keyword
from jedi.parser.representation import NamePart
from jedi._compatibility import is_py3
from jedi import common
from jedi.evaluate import compiled

View File

@@ -8,7 +8,7 @@ from jedi.evaluate import helpers
def usages(evaluator, definitions, mods):
"""
:param definitions: list of NameParts
:param definitions: list of Name
"""
def compare_array(definitions):
""" `definitions` are being compared by module/start_pos, because
@@ -34,7 +34,7 @@ def usages(evaluator, definitions, mods):
follow = [] # There might be multiple search_name's in one call_path
call_path = list(call.generate_call_path())
for i, name in enumerate(call_path):
# name is `pr.NamePart`.
# name is `pr.Name`.
if u(name) == search_name:
follow.append(call_path[:i + 1])

View File

@@ -243,7 +243,7 @@ def save_parser(path, name, parser, pickling=True):
class ParserPickling(object):
version = 17
version = 18
"""
Version number (integer) for file system cache.

View File

@@ -219,7 +219,7 @@ class Evaluator(object):
else:
types = [iterable.Array(self, current)]
else:
if isinstance(current, pr.NamePart):
if isinstance(current, pr.Name):
# This is the first global lookup.
types = self.find_types(scope, current, position=position,
search_global=True)
@@ -336,7 +336,7 @@ class Evaluator(object):
# statement name definitions. Only return, if it's one name and one
# name only. Otherwise it's a mixture between a definition and a
# reference. In this case it's just a definition. So we stay on it.
if len(call_path) == 1 and isinstance(call_path[0], pr.NamePart) \
if len(call_path) == 1 and isinstance(call_path[0], pr.Name) \
and call_path[0] in stmt.get_defined_names():
# Named params should get resolved to their param definitions.
if pr.Array.is_type(stmt.parent, pr.Array.TUPLE, pr.Array.NOARRAY) \
@@ -382,7 +382,7 @@ class Evaluator(object):
def filter_private_variable(scope, call_scope, var_name):
"""private variables begin with a double underline `__`"""
var_name = str(var_name) # var_name could be a NamePart
var_name = str(var_name) # var_name could be a Name
if isinstance(var_name, (str, unicode)) and isinstance(scope, er.Instance)\
and var_name.startswith('__') and not var_name.endswith('__'):
s = call_scope.get_parent_until((pr.Class, er.Instance, compiled.CompiledObject))

View File

@@ -87,7 +87,7 @@ def search_params(evaluator, param):
# Need to take right index, because there could be a
# func usage before.
call_path_simple = [unicode(d) if isinstance(d, pr.NamePart)
call_path_simple = [unicode(d) if isinstance(d, pr.Name)
else d for d in call_path]
i = listRightIndex(call_path_simple, func_name)
before, after = call_path[:i], call_path[i + 1:]

View File

@@ -42,7 +42,7 @@ class NameFinder(object):
types = self._names_to_types(names, resolve_decorator)
if not names and not types \
and not (isinstance(self.name_str, pr.NamePart)
and not (isinstance(self.name_str, pr.Name)
and isinstance(self.name_str.parent.parent, pr.Param)):
if not isinstance(self.name_str, (str, unicode)): # TODO Remove?
if search_global:
@@ -148,7 +148,7 @@ class NameFinder(object):
def _check_getattr(self, inst):
"""Checks for both __getattr__ and __getattribute__ methods"""
result = []
# str is important to lose the NamePart!
# str is important, because it shouldn't be `Name`!
name = compiled.create(self._evaluator, str(self.name_str))
with common.ignored(KeyError):
result = inst.execute_subscope_by_name('__getattr__', [name])
@@ -219,7 +219,7 @@ class NameFinder(object):
evaluator = self._evaluator
# Add isinstance and other if/assert knowledge.
if isinstance(self.name_str, pr.NamePart):
if isinstance(self.name_str, pr.Name):
flow_scope = self.name_str.parent.parent
# Ignore FunctionExecution parents for now.
until = flow_scope.get_parent_until(er.FunctionExecution)
@@ -455,13 +455,13 @@ def get_names_of_scope(evaluator, scope, position=None, star_search=True, includ
>>> from jedi.evaluate import Evaluator
>>> pairs = list(get_names_of_scope(Evaluator(), scope))
>>> pairs[0]
(<Function: func@3-5>, [<NamePart: y@4,4>])
(<Function: func@3-5>, [<Name: y@4,4>])
Then it yield the names from one level outer scope. For this example, this
is the most outer scope.
>>> pairs[1]
(<ModuleWrapper: <SubModule: None@1-5>>, [<NamePart: x@2,0>, <NamePart: func@3,4>])
(<ModuleWrapper: <SubModule: None@1-5>>, [<Name: x@2,0>, <Name: func@3,4>])
After that we have a few underscore names that have been defined

View File

@@ -15,7 +15,7 @@ def deep_ast_copy(obj, new_elements_default=None):
return key_value[0] not in ('_expression_list', '_assignment_details')
new_elements = new_elements_default or {}
accept = (pr.Simple, pr.NamePart, pr.KeywordStatement)
accept = (pr.Simple, pr.Name, pr.KeywordStatement)
def recursion(obj):
# If it's already in the cache, just return it.
@@ -242,7 +242,7 @@ def get_module_name_parts(module):
# token_list anymore, but for now this is the easiest way to get
# all the name_parts.
for tok in stmt_or_import._token_list:
if isinstance(tok, pr.NamePart):
if isinstance(tok, pr.Name):
name_parts.add(tok)
return name_parts
@@ -308,7 +308,7 @@ class FakeImport(pr.Import):
self.parent = parent
class FakeName(pr.NamePart):
class FakeName(pr.Name):
def __init__(self, name_str, parent=None, start_pos=(0, 0)):
super(FakeName, self).__init__(FakeSubModule, name_str, parent, start_pos)

View File

@@ -199,7 +199,7 @@ class ImportWrapper(pr.Base):
if star_imports:
scopes = [StarImportModule(scopes[0], star_imports)]
# goto only accepts Names or NameParts
# goto only accepts `Name`
if is_goto and not rest:
scopes = [s.name for s in scopes]
@@ -332,7 +332,7 @@ class _Importer(object):
self.file_path = os.path.dirname(path) if path is not None else None
def str_import_path(self):
"""Returns the import path as pure strings instead of NameParts."""
"""Returns the import path as pure strings instead of `Name`."""
return tuple(str(name_part) for name_part in self.import_path)
def get_relative_path(self):
@@ -374,12 +374,12 @@ class _Importer(object):
pos = (part._line, part._column)
try:
self.import_path = (
pr.NamePart(FakeSubModule, 'flask_' + str(part), part.parent, pos),
pr.Name(FakeSubModule, 'flask_' + str(part), part.parent, pos),
) + orig_path[3:]
return self._real_follow_file_system()
except ModuleNotFound as e:
self.import_path = (
pr.NamePart(FakeSubModule, 'flaskext', part.parent, pos),
pr.Name(FakeSubModule, 'flaskext', part.parent, pos),
) + orig_path[2:]
return self._real_follow_file_system()
return self._real_follow_file_system()

View File

@@ -176,7 +176,7 @@ class Array(use_metaclass(CachedMetaClass, IterableWrapper)):
key = key_expression_list[0]
if isinstance(key, pr.Literal):
key = key.value
elif isinstance(key, pr.NamePart):
elif isinstance(key, pr.Name):
key = str(key)
else:
continue
@@ -314,7 +314,7 @@ def _check_array_additions(evaluator, compare_array, module, is_list):
result = []
for c in calls:
call_path = list(c.generate_call_path())
call_path_simple = [unicode(n) if isinstance(n, pr.NamePart) else n
call_path_simple = [unicode(n) if isinstance(n, pr.Name) 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:

View File

@@ -316,7 +316,7 @@ def _star_star_dict(evaluator, array, expression_list, func):
for key_stmt, value_stmt in array.items():
# first index, is the key if syntactically correct
call = key_stmt.expression_list()[0]
if isinstance(call, pr.NamePart):
if isinstance(call, pr.Name):
key = call
elif isinstance(call, pr.Call):
key = call.name

View File

@@ -245,12 +245,12 @@ def get_instance_el(evaluator, instance, var, is_class_var=False):
untouched.
"""
if isinstance(var, (Instance, compiled.CompiledObject, pr.Operator, Token,
pr.Module, FunctionExecution, pr.NamePart)):
if isinstance(var, pr.NamePart):
# TODO temp solution, remove later, NameParts should never get
pr.Module, FunctionExecution, pr.Name)):
if isinstance(var, pr.Name):
# TODO temp solution, remove later, Name should never get
# here?
par = get_instance_el(evaluator, instance, var.parent, is_class_var)
return pr.NamePart(var._sub_module, unicode(var), par, var.start_pos)
return pr.Name(var._sub_module, unicode(var), par, var.start_pos)
return var
var = wrap(evaluator, var)
@@ -282,8 +282,8 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
return par
def get_parent_until(self, *args, **kwargs):
if isinstance(self.var, pr.NamePart):
# TODO NameParts should never even be InstanceElements
if isinstance(self.var, pr.Name):
# TODO Name should never even be InstanceElements
return pr.Simple.get_parent_until(self.parent, *args, **kwargs)
return pr.Simple.get_parent_until(self, *args, **kwargs)
@@ -694,7 +694,7 @@ class ModuleWrapper(use_metaclass(CachedMetaClass, pr.Module, Wrapper)):
@property
@memoize_default()
def name(self):
return pr.NamePart(self, unicode(self.base.name), self, (1, 0))
return pr.Name(self, unicode(self.base.name), self, (1, 0))
@memoize_default()
def _sub_modules(self):

View File

@@ -113,7 +113,7 @@ class Parser(object):
:return: tuple of Name, next_token
"""
def append(tok):
names.append(pr.NamePart(self.module, tok.string, None, tok.start_pos))
names.append(pr.Name(self.module, tok.string, None, tok.start_pos))
self.module.temp_used_names.append(tok.string)
names = []
@@ -139,7 +139,7 @@ class Parser(object):
self.module.temp_used_names.append(tok.string)
if tok.type != tokenize.NAME:
return None, tok
return pr.NamePart(self.module, tok.string, None, tok.start_pos), next(self._gen)
return pr.Name(self.module, tok.string, None, tok.start_pos), next(self._gen)
def _parse_import_list(self):
"""
@@ -595,7 +595,7 @@ class Parser(object):
self._scope.add_statement(kw)
if stmt is not None and tok_str == 'global':
for t in stmt._token_list:
if isinstance(t, pr.NamePart):
if isinstance(t, pr.Name):
# Add the global to the top module, it counts there.
self.module.add_global(t)
# decorator

View File

@@ -485,7 +485,7 @@ class SubModule(Scope, Module):
string = re.sub('\.[a-z]+-\d{2}[mud]{0,3}$', '', r.group(1))
# Positions are not real, but a module starts at (1, 0)
p = (1, 0)
return NamePart(self, string, self.use_as_parent, p)
return Name(self, string, self.use_as_parent, p)
@property
def has_explicit_absolute_import(self):
@@ -1240,7 +1240,7 @@ class Statement(Simple, DocstringMixin):
continue
is_literal = token_type in (tokenize.STRING, tokenize.NUMBER)
if is_literal or isinstance(tok, NamePart):
if is_literal or isinstance(tok, Name):
cls = Literal if is_literal else Call
call = cls(self._sub_module, tok_str, tok.start_pos, tok.end_pos, self)
@@ -1522,7 +1522,7 @@ class Array(StatementElement):
return "<%s: %s%s>" % (type(self).__name__, typ, self.values)
class NamePart(object):
class Name(object):
"""
A string. Sometimes it is important to know if the string belongs to a name
or not.

View File

@@ -38,7 +38,7 @@ class TestCallAndName():
def test_call_type(self):
call = self.get_call('hello')
assert isinstance(call, pr.Call)
assert type(call.name) == pr.NamePart
assert type(call.name) == pr.Name
def test_literal_type(self):
literal = self.get_call('1.0')