From c2bdda339b9db2533d16acd35dae1e4ce6e7124c Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 18 Apr 2014 01:51:09 +0200 Subject: [PATCH] again Definition/Usage merging --- jedi/api/classes.py | 14 ++++++++++++++ jedi/api/usages.py | 6 ------ jedi/refactoring.py | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/jedi/api/classes.py b/jedi/api/classes.py index cc388e0a..fa1b623f 100644 --- a/jedi/api/classes.py +++ b/jedi/api/classes.py @@ -10,6 +10,7 @@ from jedi._compatibility import next, unicode, use_metaclass from jedi import settings from jedi import common from jedi.parser import representation as pr +from jedi.cache import underscore_memoization from jedi.evaluate.cache import memoize_default, CachedMetaClass from jedi.evaluate import representation as er from jedi.evaluate import iterable @@ -529,6 +530,7 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): super(Definition, self).__init__(evaluator, definition, definition.start_pos) @property + @underscore_memoization def name(self): """ Name of variable/function/class/module. @@ -568,6 +570,10 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): except IndexError: pass return None + elif isinstance(d, iterable.Generator): + return None + elif isinstance(d, pr.NamePart): + name = d return unicode(name) @property @@ -649,6 +655,14 @@ class Definition(use_metaclass(CachedMetaClass, BaseDefinition)): iterable = list(iterable) return list(chain.from_iterable(iterable)) + def __eq__(self, other): + return self._start_pos == other._start_pos \ + and self.module_path == other.module_path \ + and self.name == other.name + + def __hash__(self): + return hash((self._start_pos, self.module_path, self.name)) + class CallSignature(Definition): """ diff --git a/jedi/api/usages.py b/jedi/api/usages.py index f984b778..d93e247f 100644 --- a/jedi/api/usages.py +++ b/jedi/api/usages.py @@ -1,4 +1,3 @@ -from jedi._compatibility import unicode from jedi import common from jedi.api import classes from jedi.parser import representation as pr @@ -11,13 +10,8 @@ class Usage(classes.Definition): def __init__(self, evaluator, name_part, scope): super(Usage, self).__init__(evaluator, name_part) self._start_pos = name_part.start_pos - self.text = unicode(name_part) #self.end_pos = name_part.end_pos - @property - def description(self): - return "%s@%s,%s" % (self.text, self.line, self.column) - def __eq__(self, other): return self._start_pos == other._start_pos \ and self.module_path == other.module_path diff --git a/jedi/refactoring.py b/jedi/refactoring.py index 86b55e19..726ff6fd 100644 --- a/jedi/refactoring.py +++ b/jedi/refactoring.py @@ -89,7 +89,7 @@ def _rename(names, replace_str): nr, indent = name.line, name.column line = new_lines[nr - 1] new_lines[nr - 1] = line[:indent] + replace_str + \ - line[indent + len(name.text):] + line[indent + len(name.name):] process(current_path, old_lines, new_lines) return dct