Comments (5)
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.
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.
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.
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.
Great, just ran it with 0.3 over my code, and it found a few extra places to correct.
from redbaron.
Related Issues (20)
- [BUG] `return` on the 1-2 indent levels levels inside of `try`/`except` resets the closes `except` level HOT 5
- replacing a call atom with a comprehension raises ParsingError
- ComprehensionLoopNode target/iterator attributes transposed
- Misleading AST for modulo operator combined with multiplication HOT 1
- Please add a LICENSE file
- Conversion to ast ASTs
- Incorrect parsing of Unicode Literals. Got - UntreatedError: Untreated elements
- Middle-ground betwixt `ast` and `baron` for parsing source code, and emitting only what changed in FST from AST HOT 1
- bug: Comments determine indent level of function body
- GroupingError on await expression
- RedBaron confuse relative path to ellipsis in from_imports
- py.test tests failing
- bug: Unpacking operator `*` used in list gives an error HOT 2
- support for walrus operator
- support for context manager tuple
- Unsupported positional-only argument syntax
- Indent of function docstrings always four spaces HOT 2
- Sort functions by their usage?
- FromImportNode modifyed in memory but not saved to the file
- bug: remove() doesn't perform well. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redbaron.