From 8236ce18a2ac96a33e075a46b9931e38384ce1bc Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Thu, 9 Oct 2014 03:23:52 +0200 Subject: [PATCH] Refactor Literal. --- jedi/parser/representation.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/jedi/parser/representation.py b/jedi/parser/representation.py index c42314d9..3dceeac9 100644 --- a/jedi/parser/representation.py +++ b/jedi/parser/representation.py @@ -191,7 +191,6 @@ class Name(_Leaf): # Unfortunately there's no way to use slots for str (non-zero __itemsize__) # -> http://utcc.utoronto.ca/~cks/space/blog/python/IntSlotsPython3k # Therefore don't subclass `str`. - __slots__ = ('_string', '_line', '_column') def __str__(self): return self.value @@ -207,6 +206,18 @@ class Name(_Leaf): return self.get_parent_until((ArrayStmt, StatementElement), reverse=True) +class Literal(_Leaf): + def eval(self): + return literal_eval(self.value) + + def __repr__(self): + if is_py3: + s = self.literal + else: + s = self.literal.encode('ascii', 'replace') + return "<%s: %s>" % (type(self).__name__, s) + + class Operator(_Leaf): def __str__(self): return self.get_code() @@ -1444,25 +1455,6 @@ class Call(StatementElement): return "<%s: %s>" % (type(self).__name__, self.name) -class Literal(StatementElement): - __slots__ = ('literal', 'value') - - def __init__(self, module, literal, start_pos, end_pos, parent=None): - super(Literal, self).__init__(module, start_pos, end_pos, parent) - self.literal = literal - self.value = literal_eval(literal) - - def get_code(self): - return self.literal + super(Literal, self).get_code() - - def __repr__(self): - if is_py3: - s = self.literal - else: - s = self.literal.encode('ascii', 'replace') - return "<%s: %s>" % (type(self).__name__, s) - - class Array(StatementElement): """ Describes the different python types for an array, but also empty