diff --git a/jedi/parser/python/tree.py b/jedi/parser/python/tree.py index 373b676d..942e271b 100644 --- a/jedi/parser/python/tree.py +++ b/jedi/parser/python/tree.py @@ -41,8 +41,7 @@ import abc from jedi._compatibility import (Python3Method, is_py3, utf8_repr, literal_eval, unicode) -from jedi.parser.tree import (Node, BaseNode, Leaf, LeafWithNewlines, - ErrorNode, ErrorLeaf) +from jedi.parser.tree import Node, BaseNode, Leaf, ErrorNode, ErrorLeaf def _safe_literal_eval(value): @@ -211,8 +210,12 @@ class PythonLeaf(Leaf, PythonMixin): pass -class PythonLeafWithNewlines(LeafWithNewlines, PythonMixin): - pass +class _LeafWithoutNewlines(PythonLeaf): + __slots__ = () + + @property + def end_pos(self): + return self.line, self.indent + len(self.value) class PythonBaseNode(BaseNode, PythonMixin): @@ -231,12 +234,12 @@ class PythonNode(Node, PythonMixin): pass -class EndMarker(PythonLeaf): +class EndMarker(_LeafWithoutNewlines): __slots__ = () type = 'endmarker' -class Newline(PythonLeafWithNewlines): +class Newline(PythonLeaf): """Contains NEWLINE and ENDMARKER tokens.""" __slots__ = () type = 'newline' @@ -246,7 +249,7 @@ class Newline(PythonLeafWithNewlines): return "<%s: %s>" % (type(self).__name__, repr(self.value)) -class Name(PythonLeaf): +class Name(_LeafWithoutNewlines): """ A string. Sometimes it is important to know if the string belongs to a name or not. @@ -286,7 +289,7 @@ class Name(PythonLeaf): yield self -class Literal(PythonLeafWithNewlines): +class Literal(PythonLeaf): __slots__ = () def eval(self): @@ -303,7 +306,7 @@ class String(Literal): __slots__ = () -class Operator(PythonLeaf): +class Operator(_LeafWithoutNewlines): type = 'operator' __slots__ = () @@ -328,7 +331,7 @@ class Operator(PythonLeaf): return hash(self.value) -class Keyword(PythonLeaf): +class Keyword(_LeafWithoutNewlines): type = 'keyword' __slots__ = () diff --git a/jedi/parser/tree.py b/jedi/parser/tree.py index 4c28c4f1..c2044a2b 100644 --- a/jedi/parser/tree.py +++ b/jedi/parser/tree.py @@ -115,10 +115,6 @@ class Leaf(_NodeOrLeaf): return self.line - self.prefix.count('\n'), 0 # It's the first leaf. return previous_leaf.end_pos - @property - def end_pos(self): - return self.line, self.indent + len(self.value) - def move(self, line_offset): self.line += line_offset @@ -139,14 +135,6 @@ class Leaf(_NodeOrLeaf): def nodes_to_execute(self, last_added=False): return [] - @utf8_repr - def __repr__(self): - return "<%s: %s start=%s>" % (type(self).__name__, self.value, self.start_pos) - - -class LeafWithNewlines(Leaf): - __slots__ = () - @property def end_pos(self): """ @@ -164,7 +152,7 @@ class LeafWithNewlines(Leaf): @utf8_repr def __repr__(self): - return "<%s: %r>" % (type(self).__name__, self.value) + return "<%s: %s start=%s>" % (type(self).__name__, self.value, self.start_pos) class BaseNode(_NodeOrLeaf): @@ -335,7 +323,7 @@ class ErrorNode(BaseNode): return [] -class ErrorLeaf(LeafWithNewlines): +class ErrorLeaf(Leaf): """ TODO doc """