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
I have some new features I want to share with the yapf community.
This is also a response to issue #194 and issue #346.
The alignment feature added is referred to the yapf function _AlignTrailingComments(final_lines).
The knobs
The main functions for all the knobs are added in reformatter.py.
knob: ALIGN_ARGUMENT_ASSIGNMENT
This is an option to align the assignment operators of each block inside the argument list of a function call or a function definition.
The condition : it is only effective if all arguments inside the argument list are placed on separate lines.
The case when the typed argument name is too long that it has newlines, we can increase the column limit, otherwise it will be aligned with the last line of the unwrapped typed argument name that has the assignment operator:
An object(a list/a dictionary/an argument list/ a set/a function call, etc.) with its items in newlines in between creates a new block inside the argument list of the same level:
This option is made under the consideration that some programmers may prefer to remain the alignment with comment lines inside.
If it is set False, a comment line in between won't create a new alignment block. Entries before and after the comment line/lines will align with their assignment operators.
Preparations
To make the alignment functions possible, some other changes are made to other files.
subtype_assigner.py: a change is made to include the subtype TYPED_NAME_ARG_LIST to all tokens inside typed argument name. This is to recognize all tokens before '=' of very long typed name in arguments with typed names, e.g., a typed argument as below:
I left a comment on the original issue saying hope it gets attention of reviewers. It is frustrating to see no reviewers picked those PRs up yet for 3 months.
@lizawang Since the devs seem quite slow to merge these PRs, would you make a branch in your fork that integrates them all or would you assist me in doing so?
I already tried, but not knowing the inner workings of yapf I don't really know how to solve the merge conflicts that happen when I try to merge 2 or more of your PR branches
Hello JackLilhammers, I'm glad that you like the features. If you want to use all alignment features, you can go to my forked yapf and use the branch called "feature_align_assignment_and_dictColon" which has alignment features for both assignments (including argument assignment) and colons in dictionaries. You can also use the branch "nemetris" which in addition has some fixes for inline comment alignment.
@lizawang I downloaded your "feature_align_assignment_and_dictColon" branch. I'm trying to build your branched version of yapf so that I can use it instead on my Windows-based machine. I've executed "python setup.py build", but I don't see a yapf.exe built. Do you know how I can build yapf.exe and then install it locally -- or a guide that shows how this is done for python projects in general? Many thanks!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello all yapf founders!
I have some new features I want to share with the yapf community.
This is also a response to issue #194 and issue #346.
The alignment feature added is referred to the yapf function _AlignTrailingComments(final_lines).
The knobs
The main functions for all the knobs are added in reformatter.py.
knob: ALIGN_ARGUMENT_ASSIGNMENT
This is an option to align the assignment operators of each block inside the argument list of a function call or a function definition.
The condition : it is only effective if all arguments inside the argument list are placed on separate lines.
The case when the typed argument name is too long that it has newlines, we can increase the column limit, otherwise it will be aligned with the last line of the unwrapped typed argument name that has the assignment operator:
New block of arguments starts with new alignment. There are 3 cases featured as an indication for new alignment block:
knob: NEW_ALIGNMENT_AFTER_COMMENTLINE
This option is made under the consideration that some programmers may prefer to remain the alignment with comment lines inside.
Preparations
To make the alignment functions possible, some other changes are made to other files.
subtype_assigner.py: a change is made to include the subtype TYPED_NAME_ARG_LIST to all tokens inside typed argument name. This is to recognize all tokens before '=' of very long typed name in arguments with typed names, e.g., a typed argument as below:
format_token.py: necessary boolean functions are added, is_argassign, is_argname, is_argname_start.
Finally
In the end, the knobs are added into the style.py and tests for each one are also updated in yapftests folder.