summaryrefslogtreecommitdiff
path: root/tokens.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-08-09 14:17:45 +0200
committerAnthon van der Neut <anthon@mnt.org>2017-08-09 14:17:45 +0200
commit291b2e6757d22061acb8ee9a581dc04e3a791847 (patch)
tree3f805ec3551ba2e0baa5ce21b1ebadfd3136ccc5 /tokens.py
parentb3b5301e1b0a21d81a2ec1501df9ef92abac5ce2 (diff)
downloadruamel.yaml-291b2e6757d22061acb8ee9a581dc04e3a791847.tar.gz
fix for indenting non-indented sequence after comment
- solves several expected to fail and fixes two incorrect tests (test_09-Sammy Sosa & test_before_nested_seq_from_scratch) - still swaps foo and bar on test_issue_25_03
Diffstat (limited to 'tokens.py')
-rw-r--r--tokens.py21
1 files changed, 17 insertions, 4 deletions
diff --git a/tokens.py b/tokens.py
index e5bac6b..99f4b19 100644
--- a/tokens.py
+++ b/tokens.py
@@ -4,6 +4,7 @@
if False: # MYPY
from typing import Any, Dict, Optional, List # NOQA
+SHOWLINES = True
class Token(object):
__slots__ = 'start_mark', 'end_mark', '_comment',
@@ -15,12 +16,18 @@ class Token(object):
def __repr__(self):
# type: () -> Any
- attributes = [key for key in self.__slots__ if not key.endswith('_mark') and
- hasattr('self', key)]
+ # attributes = [key for key in self.__slots__ if not key.endswith('_mark') and
+ # hasattr('self', key)]
+ attributes = [key for key in self.__slots__ if not key.endswith('_mark')]
attributes.sort()
arguments = ', '.join(['%s=%r' % (key, getattr(self, key))
for key in attributes])
- return '%s(%s)' % (self.__class__.__name__, arguments)
+ if SHOWLINES:
+ try:
+ arguments += u', line: ' + str(self.start_mark.line)
+ except:
+ pass
+ return u'{}({})'.format(self.__class__.__name__, arguments)
def add_post_comment(self, comment):
# type: (Any) -> None
@@ -261,4 +268,10 @@ class CommentToken(Token):
def __repr__(self):
# type: () -> Any
- return 'CommentToken({!r})'.format(self.value)
+ v = self.value
+ if SHOWLINES:
+ try:
+ v += u', line: ' + str(self.start_mark.line)
+ except:
+ pass
+ return 'CommentToken({!r})'.format(v)