Closed remram44 closed 7 years ago
This is possibly a bug in baron.
If the script starts with the comment, I get:
[{'formatting': [{'formatting': [],
'type': 'comment',
'value': '# MODULE 1 org.vistrails.vistrails.basic:Integer'}],
'indent': '',
'type': 'endl',
'value': '\n'},
If I insert a blank line before:
[{'formatting': [], 'indent': '', 'type': 'endl', 'value': '\n'},
{'formatting': [],
'type': 'comment',
'value': '# MODULE 1 org.vistrails.vistrails.basic:Integer'}]
Hello,
This is actually a known bug in baron https://github.com/Psycojoker/baron/issues/44. Comments are very annoying thing to handle because they aren't present in python grammar and that I end up my default putting them on endl node to circumvent this situation and I sometime extract them from the endl node, sometime not, this is not a very great situation but I haven't managed yet to find a better solution for now.
Thanks for reporting,
Ok, since I'm having rethinking about this problem something like every 2 months and that I end up on the same blocking point each time, let's write it here:
# foo
if a: # foo\n bar
1 + 1 # foo
Possible solutions:
@remram44 Thanks to https://github.com/PyCQA/baron/pull/88, this is now fixed in master baron. I've tested your issue in redbaron with the latest baron master:
In [7]: script = redbaron.RedBaron("""\
...: # some comment
...: a = 2
...: """)
...: script
...:
Out[7]:
0 # some comment
1 a = 2
In [9]: script[0].dumps()
Out[9]: '# some comment'
In [10]: script[0].help()
CommentNode()
# identifiers: comment, comment_, commentnode
value='# some comment'
So I'm closing this issue now but don't hesitate to reopen it if needed. Thanks for the report :+1:
Fix has been released https://pypi.python.org/pypi/redbaron/0.6.3
Somehow I get an EndlNode that renders to a comment... really not sure what is going on here.
Example notebook