Giter Club home page Giter Club logo

Comments (5)

Psycojoker avatar Psycojoker commented on September 28, 2024

Hello,

The problem you are facing right now is that, by default, RedBaron hides from you the comma tokens using ProxyList has described here: https://redbaron.readthedocs.org/en/latest/proxy_list.html The unproxyfied list is accessible using ".node_list": https://redbaron.readthedocs.org/en/latest/proxy_list.html#access-the-unproxified-node-list

You have several solutions to go to the last comma:

from redbaron import RedBaron
red = RedBaron("(self, )")
red[0].value.node_list[-1].second_formatting = ""
red[0]("comma", recursive=False)[-1]

Is this help? I'm wondering on how to makes this more obvious to people (this is already describe at the end of the tutorial and in the documentation :/).

from redbaron.

kayhayen avatar kayhayen commented on September 28, 2024

Hello Laurent,

You have several solutions to go to the last comma:

from redbaronimport RedBaron
red= RedBaron("(self, )")
red[0].value.node_list[-1].second_formatting= ""
red0[-1]

That works, with the gotcha, that I need to consider "with_parenthesis",
or else I remove it for such code as well:

a, = b

which is different (to me) from

(a, ) = b

A relatively constant theme, is that I do not always agree, where
spaces are allocated. I would want to assign the space before and
after theequals sign to an assignment node, never the rvalue and
lvalue.

I understand for strings, that "a" "b" is legal, and that the
whitespace needs storage, while it's still a string node.

But this leads to calls:

call( 1 )
call( "a" )

having entirely different assignment of spaces for the call node.

So my code checks for string arguments, and treats them differently, as
it does for bytestrings, and raw strings. I am tempted to raise an issue
for this. I think for the last string, it should not consume any spaces
but leave them to its parent.

But I don't understand the difficulties of inserting items properly
formatted in the same way. Maybe it's not even feasible to get what I
consider the natural assignment of spaces.

Yours,
Kay

from redbaron.

Psycojoker avatar Psycojoker commented on September 28, 2024

That works, with the gotcha, that I need to consider "with_parenthesis",
or else I remove it for such code as well:

a, = b

which is different (to me) from

(a, ) = b

A solution for this case would be to always remove it from the last
comma of the tuple and always put it on the left side of the "=".

I don't know if this is an acceptable solution for you, please let me
know.

A relatively constant theme, is that I do not always agree, where
spaces are allocated. I would want to assign the space before and
after theequals sign to an assignment node, never the rvalue and
lvalue.

I understand for strings, that "a" "b" is legal, and that the
whitespace needs storage, while it's still a string node.

But this leads to calls:

call( 1 )
call( "a" )

having entirely different assignment of spaces for the call node.

So my code checks for string arguments, and treats them differently, as
it does for bytestrings, and raw strings. I am tempted to raise an issue
for this. I think for the last string, it should not consume any spaces
but leave them to its parent.

Indeed, you are correct, the string here are greedy on getting
surrounding formatting tokens. I'm going to open an issue for that. I
think this is fixable (probably taking the approach you are
suggesting) but might take me some time.

Laurent Peuch -- Bram

from redbaron.

Psycojoker avatar Psycojoker commented on September 28, 2024

String aren't greedy anymore so this shouldn't be a problem now, don't hesitate to complain if it's still the case.

from redbaron.

kayhayen avatar kayhayen commented on September 28, 2024

Great, just ran it with 0.3 over my code, and it found a few extra places to correct.

from redbaron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.