Skip to content

Commit

Permalink
convert to str type
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinwan committed Nov 19, 2017
1 parent 22ca50b commit 8e73c43
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions TexSoup/utils.py
Expand Up @@ -50,16 +50,24 @@ def wrap(*args, **kwargs):
#########################


class TokenWithPosition(object):
def __init__(self, text, position):
class TokenWithPosition(str):
"""Enhanced string object with knowledge of global position."""

def __new__(cls, text, position):
"""Initializer for pseudo-string object.
:param text: The original string
:param position: Position in the original buffer
"""
self = str.__new__(cls, text)
if isinstance(text, TokenWithPosition):
self.text, self.position = text.text, text.position
else:
self.text = text
self.position = position
return self

def __repr__(self):
# return '{}:{}'.format(self.position, repr(self.text))
return repr(self.text)

def __str__(self):
Expand Down

0 comments on commit 8e73c43

Please sign in to comment.