forked from VimPlug/jedi
Refactor Literal.
This commit is contained in:
@@ -191,7 +191,6 @@ class Name(_Leaf):
|
|||||||
# Unfortunately there's no way to use slots for str (non-zero __itemsize__)
|
# Unfortunately there's no way to use slots for str (non-zero __itemsize__)
|
||||||
# -> http://utcc.utoronto.ca/~cks/space/blog/python/IntSlotsPython3k
|
# -> http://utcc.utoronto.ca/~cks/space/blog/python/IntSlotsPython3k
|
||||||
# Therefore don't subclass `str`.
|
# Therefore don't subclass `str`.
|
||||||
__slots__ = ('_string', '_line', '_column')
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.value
|
return self.value
|
||||||
@@ -207,6 +206,18 @@ class Name(_Leaf):
|
|||||||
return self.get_parent_until((ArrayStmt, StatementElement), reverse=True)
|
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):
|
class Operator(_Leaf):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.get_code()
|
return self.get_code()
|
||||||
@@ -1444,25 +1455,6 @@ class Call(StatementElement):
|
|||||||
return "<%s: %s>" % (type(self).__name__, self.name)
|
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):
|
class Array(StatementElement):
|
||||||
"""
|
"""
|
||||||
Describes the different python types for an array, but also empty
|
Describes the different python types for an array, but also empty
|
||||||
|
|||||||
Reference in New Issue
Block a user