-
Notifications
You must be signed in to change notification settings - Fork 895
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
Option to align multiple assignments #194
Comments
I would like to know how often this is done before putting a lot of effort into it...:-) |
This option would be useful to us |
As long as it remained an option, I'd be fine with it. If someone would like to contribute it, that would be keen. :-) |
Has anyone built a fork that includes this? If not, I might consider building it as I think vertical alignment of assignments makes for easier to read code. |
I would also very much appreciate that feature :-) |
Would also love this feature |
This knob/option is sorely needed. If anyone understands the utility/significance of clean vertical alignment through the use of whitespace, it should be python programmers! :) Detecting aligned equals signs in a code block doesn't seem like it would be that difficult (especially since comments can already be aligned within a block). However, there are other vertical alignment situations, such as columnar alignment in embedded data/dispatch tables, that might be tricky to achieve unless 100% consistent (although that is obviously out of scope for this issue). Until this issue is resolved (if ever), a workaround for anyone arriving here is to suppress yapf formatting with the use of comment directives around the block: # yapf: disable
C_CHED = 1234
C_BRIE = 5678
C_3 = 9012
C_4 = 3456
my_lookup = (
# function foo bar baz qux
# -------- --- --- --- ---
(my_func1, False, "cheddar", 1,12, C_CHED),
(some_other_fn, False, "brie", 3.19, C_BRIE),
(f2, True, "camembert", 0.57, C_3),
(your_fn3, False, "stilton", 9.99, C_4),
)
# yapf: enable Without these directives, yapf completely mangles such alignments (and so does any other formatter I can find). Adding the comment clutter is a bit frustrating, but there are definitely many cases when this is better than mangling the alignment. |
In case this does ever get worked on (even if by me), I'll add some more notes... It would be nice to go further and preserve alignment for more than just equals signs. Maybe an option along the lines of this:
When enabled, yapf could try and detect and preserve alignments such as this: len1 = (foo + 12) - somevar
len2 = (longer_var + 19) - x
l3 = (an_even_longer_var + 19) - x
l3 = (yyy + 4) - a_really_long_var_name_that_is_right_here However, this could get confusing/complex if different symbols are used ( len1 = (foo + 12) - somevar
#len2 = (longer_var + 19) - x
l3 = (an_even_longer_var + 19) - x
l3 = ((yyy + 9) + 4) + a_really_long_var_name_that_is_right_here My opinion on that example block is that it would still be be untouched with the alignment feature enabled. Reasons being: A) the commented line should be ignored from an alignment perspective (could be a pure comment); B) the the Additional notes/ideas:
|
this would be amazing for us as well |
I definitely prefer vertical alignment of assignment. |
After 5 years, this is still an open issue... |
"After 5 years, this is still an open issue..." -- yapf is Open Source, and no doubt a contribution would be accepted. |
alignment is a must for human reader of python code. |
Is somebody currently working on this feature? Otherwise I would try implementing it. |
I don't think anyone's working on it at the moment. Please give it a shot! :-) |
Overall ,
having easy to human read code
is beneficial to spot bugs/ potential issues quickly
… On Mar 9, 2022, at 17:37, Bill Wendling ***@***.***> wrote:
I don't think anyone's working on it at the moment. Please give it a shot! :-)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
You are receiving this because you commented.
|
This would be awesome! |
Definitely a must have for readability. |
As I see, last PRs made this functionality available and are ready to review. Wonder if reviewers have seen it yet |
Please review it, after many years of waiting ! |
In the Perl world, perltidy do well on the assignment align. |
Please review the PRs for this issue. The features they provide would allow use to implement our style guide in yapf other than the vertical alignment of import statments using the "from X import A, B, C" style. |
Often the following convention is used:
whilst this is against pep8, it seems like this would be a nice option to support for those people that are (forced??) to use this convention.
The text was updated successfully, but these errors were encountered: