From 522c9eda906c08537cc553b1da33c06819448c6e Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 26 Sep 2014 16:18:10 +0200 Subject: [PATCH] Remove pr.Name completely. --- jedi/api/__init__.py | 8 +--- jedi/evaluate/finder.py | 10 +---- jedi/parser/representation.py | 59 +++--------------------------- test/test_evaluate/test_helpers.py | 9 ----- 4 files changed, 9 insertions(+), 77 deletions(-) diff --git a/jedi/api/__init__.py b/jedi/api/__init__.py index fa6715e4..831353b5 100644 --- a/jedi/api/__init__.py +++ b/jedi/api/__init__.py @@ -179,9 +179,6 @@ class Script(object): comps = [] comp_dct = {} for c, s in set(completions): - # TODO Remove this line. c should be a namepart even before that. - if c.isinstance(pr.Name): - c = c.names[-1] n = str(c) if settings.case_insensitive_completion \ and n.lower().startswith(like.lower()) \ @@ -396,10 +393,9 @@ class Script(object): definitions = set(self._prepare_goto(goto_path)) definitions = resolve_import_paths(definitions) - names = [s if isinstance(s, pr.Name) else s.name for s in definitions + names = [s.name for s in definitions if s is not imports.ImportWrapper.GlobalNamespace] - defs = [classes.Definition(self._evaluator, name.names[-1] if isinstance(name, pr.Name) else name ) - for name in names] + defs = [classes.Definition(self._evaluator, name) for name in names] return helpers.sorted_definitions(set(defs)) def goto_assignments(self): diff --git a/jedi/evaluate/finder.py b/jedi/evaluate/finder.py index 33188bbf..563d0c87 100644 --- a/jedi/evaluate/finder.py +++ b/jedi/evaluate/finder.py @@ -102,20 +102,14 @@ class NameFinder(object): or isinstance(scope, compiled.CompiledObject) \ or isinstance(stmt, pr.ExprStmt) and stmt.is_global(): # Always reachable. - if isinstance(name, pr.Name): - names.append(name.names[-1]) - else: - names.append(name) + names.append(name) else: check = flow_analysis.break_check(self._evaluator, name_list_scope, er.wrap(self._evaluator, scope), self.scope) if check is not flow_analysis.UNREACHABLE: - if isinstance(name, pr.Name): - names.append(name.names[-1]) - else: - names.append(name) + names.append(name) if check is flow_analysis.REACHABLE: break diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index 27feec58..d928a9d7 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -795,11 +795,11 @@ class Import(Simple): :param start_pos: Position (line, column) of the Import. :type start_pos: tuple(int, int) :param namespace_names: The import, can be empty if a star is given - :type namespace_names: Name + :type namespace_names: list of Name :param alias: The alias of a namespace(valid in the current namespace). - :type alias: Name + :type alias: list of Name :param from_names: Like the namespace, can be equally used. - :type from_names: Name + :type from_names: list of Name :param star: If a star is used -> from time import *. :type star: bool :param defunct: An Import is valid or not. @@ -940,9 +940,6 @@ class Statement(Simple, DocstringMixin): self._token_list = token_list self._names_are_set_vars = names_are_set_vars if set_name_parents: - for t in token_list: - if isinstance(t, Name): - t.parent = self.use_as_parent for n in as_names: n.parent = self.use_as_parent self._doc_token = None @@ -1120,7 +1117,7 @@ class Statement(Simple, DocstringMixin): first = False if isinstance(tok, Base): - # the token is a Name, which has already been parsed + # The token is a Name, which has already been parsed. if not level: if isinstance(tok, ListComprehension): # it's not possible to set it earlier @@ -1190,9 +1187,6 @@ class Statement(Simple, DocstringMixin): added_breaks=added_breaks) if stmt is not None: - for t in stmt._token_list: - if isinstance(t, Name): - t.parent = stmt stmt._names_are_set_vars = names_are_set_vars return stmt, tok @@ -1226,7 +1220,7 @@ class Statement(Simple, DocstringMixin): next(token_iterator, None) continue else: - # the token is a Name, which has already been parsed + # The token is a Name, which has already been parsed tok_str = tok token_type = None @@ -1577,49 +1571,6 @@ class NamePart(object): return self.start_pos[0], self.start_pos[1] + len(self._string) -class Name(Simple): - """ - Used to define names in python. - Which means the whole namespace/class/function stuff. - So a name like "module.class.function" - would result in an array of [module, class, function] - """ - __slots__ = ('names', '_get_code') - - def __init__(self, module, names, start_pos, end_pos, parent=None): - super(Name, self).__init__(module, start_pos, end_pos, parent) - # Cache get_code, because it's used quite often for comparisons - # (seen by using the profiler). - self._get_code = ".".join(n[0] for n in names) - - names = tuple(NamePart(module, n[0], self, n[1]) for n in names) - self.names = names - - def get_code(self): - """ Returns the names in a full string format """ - return self._get_code - - def get_definition(self): - # TODO This is way to complicated, simplify this with a new parser. - return self.get_parent_until((ArrayStmt, StatementElement), reverse=True) - return self.get_parent_until((ExprStmt, IsScope, Import)) - - @property - def end_pos(self): - return self.names[-1].end_pos - - @property - def docstr(self): - """Return attribute docstring (PEP 257) if exists.""" - return self.parent.docstr - - def __str__(self): - return self.get_code() - - def __len__(self): - return len(self.names) - - class ListComprehension(ForFlow): """ Helper class for list comprehensions """ def __init__(self, module, stmt, middle, input, parent): diff --git a/test/test_evaluate/test_helpers.py b/test/test_evaluate/test_helpers.py index c6ba5c33..056ba98e 100644 --- a/test/test_evaluate/test_helpers.py +++ b/test/test_evaluate/test_helpers.py @@ -1,18 +1,9 @@ from jedi._compatibility import unicode from jedi.evaluate import helpers -from jedi.parser import representation as pr from jedi.parser import Parser -def test_deep_ast_copy(): - name = pr.Name(object, [('hallo', (0, 0))], (0, 0), (0, 0)) - - # fast parent copy should switch parent - new_name = helpers.deep_ast_copy(name) - assert new_name.names[0].parent == new_name - - def test_statement_elements_in_statement(): def get_stmt_els(string): p = Parser(unicode(string))