You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If you iterate on a function node and issue "dumps" on each line, then any if/else block is incorrectly indented.
Use this code to reproduce the problem
In [1]: importredbaronIn [2]: code=""" ...: def foo(): ...: simple_code() ...: # a comment ...: if x is True: ...: add() ...: else: ...: sub() ...: """In [3]: tree=redbaron.RedBaron(code)
In [4]: defnode=tree[1]
In [5]: type(defnode)
Out[5]: redbaron.nodes.DefNodeIn [6]: forlineindefnode:
...: print(line.dumps())
...:
simple_code()
# a commentifxisTrue:
add()
else:
sub()
As you can see above if and else are not in the same vertical alignment.
As per my use case I am extracting all the metadata from the attributes of the defnode and I need to unparse the function body line by line. I am able to do it easily with ast by I am loosing all the code comments, which I want to preserve. If somehow this indentation issue is resolved, then I am all done !
The text was updated successfully, but these errors were encountered:
If you iterate on a function node and issue
"dumps"
on each line, then anyif/else
block is incorrectly indented.Use this code to reproduce the problem
As you can see above
if
andelse
are not in the same vertical alignment.As per my use case I am extracting all the metadata from the attributes of the
defnode
and I need tounparse
the function body line by line. I am able to do it easily withast
by I am loosing all the code comments, which I want to preserve. If somehow this indentation issue is resolved, then I am all done !The text was updated successfully, but these errors were encountered: