Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot modify whitespace from function declarations #59

Closed
kayhayen opened this issue Feb 22, 2015 · 5 comments
Closed

Cannot modify whitespace from function declarations #59

kayhayen opened this issue Feb 22, 2015 · 5 comments

Comments

@kayhayen
Copy link

Hello,

having a function:

def f( a, b ):
pass

I would like to set third_formatting and fourth_formatting on it, but it says "unhandled case", when I set this to "". My intent is to write code, which automatically formats function definition arguments to
contain new-lines as necessary only, and no leading or trailing space for arguments.

Can you please add support for these.

@Psycojoker
Copy link
Member

Hello,

I've just pushed a patch to fix this (and this will basically be fixed for every "code block node" https://redbaron.readthedocs.org/en/latest/nodes_reference.html#codeblocknode). Sorry for the big delay, life isn't very compelling with me for redbaron right now :/

Waiting for your feedback,

@kayhayen
Copy link
Author

Hello there,

I just pip installed things, and can confirm, that the function white space is now properly writable, for what I use:

# This is between "def" and function name.
def_node.first_formatting = " "

# This is after the opening/closing brace, we don't want it there.
def_node.third_formatting = ""
def_node.fourth_formatting = ""

# This is to insert/remove spaces or new lines, depending on line length
# so far, but is not functional at all.
for argument_node in def_node.arguments:
    argument_node.first_formatting = ""
    argument_node.second_formatting = " "

However, the last part doesn't work at all, nothing changes, whatever I assign there. I would like
to be able to modify a function like this:

def f(a, b):
    pass

to become

 def f(a,
       b):
     pass

with the choice of " " or "\n" depending on accumulated line length so far.

Yours,
Kay

@kayhayen
Copy link
Author

Meanwhile I have observed and effect of

argument_node.first_formatting

for keyword argument, it allows to assign spaces before the "=". I guess, I might have to check the argument type, or look for more formatting values.

@ibizaman
Copy link
Collaborator

I guess that's a style decision and not a RedBaron bug, right ?

@Psycojoker
Copy link
Member

Hello,

The "\n" needs to be put on the CommaNode here, as you have guessed, the formatting for the ArgumentNode are formatting regarding the stuff arround the "=" when its present.

I'm closing this ticket, one is already open in baron repo regarding generating detailed doc on the rendering of nodes, that would hopefully have made you this information way more accessible for you.

Kind regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants