PyCQA / redbaron

Bottom-up approach to refactoring in python
http://redbaron.pycqa.org/
698 stars 74 forks source link

EndlNode instead of CommentNode #67

Closed remram44 closed 7 years ago

remram44 commented 9 years ago

Somehow I get an EndlNode that renders to a comment... really not sure what is going on here.

Example notebook

remram44 commented 9 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'}]
Psycojoker commented 9 years ago

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,

Psycojoker commented 9 years ago

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:

Possible solutions:

ibizaman commented 7 years ago

@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:

Psycojoker commented 7 years ago

Fix has been released https://pypi.python.org/pypi/redbaron/0.6.3