PyCQA / redbaron

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

commentNode not shown by help when next to if-statement #135

Open Thijs-Riezebeek opened 7 years ago

Thijs-Riezebeek commented 7 years ago
if True:  # My comment
    pass

This gives the following output (using bpython):

>>> from redbaron import RedBaron
>>>
>>> with open('input_files/comment_after_statement_same_line.py') as f:
...     fst = RedBaron(f.read())
...     print fst.help(True)
...
...
0 -----------------------------------------------------
IfelseblockNode()
  # identifiers: ifelseblock, ifelseblock_, ifelseblocknode
  value ->
    * IfNode()
        # identifiers: if, if_, ifnode
        test ->
          NameNode()
            # identifiers: name, name_, namenode
            value='True'
        value ->
          * PassNode()
              # identifiers: pass, pass_, passnode
None

In the above scenario, the commentNode is not shown by method, however when calling .dumps(), the code is correctly restructured, including the comment.

Thijs-Riezebeek commented 7 years ago

Any ideas on this? Is there a work around to detecting the comment node? Cause that is my goal here, detecting the comment.