-
Notifications
You must be signed in to change notification settings - Fork 899
Feature align assignment (continuation of PR#1030) #1281
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
Open
Andrea-Oliveri
wants to merge
22
commits into
google:main
Choose a base branch
from
Andrea-Oliveri:feature_align_assignment
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Feature align assignment (continuation of PR#1030) #1281
Andrea-Oliveri
wants to merge
22
commits into
google:main
from
Andrea-Oliveri:feature_align_assignment
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Good afternoon,
this is a continuation of @lizawang's pull request titled
Feature align assignment
, PR#1030 .I have addressed all the PR comments by @bwendling.
Of note:
NEW_ALIGNMENT_AFTER_COMMENTLINE
toALIGN_ASSIGNMENT_RESTART_AFTER_COMMENTS
, as recommended._AlignAssignment
into multiple smaller functions._AlignAssignment
was heavily, heavily inspired from_AlignTrailingComments
, I decided to group the common logic into a single generic function which takes callbacks for the specific tasks._AlignTrailingComments
to its previous state and we can keep duplicated logic.main
branch.Copied here, the description of PR#1030 with minor changes:
The knobs
The main functions for all the knobs are added in reformatter.py.
knob: ALIGN_ASSIGNMENT
This is an option to align the assignment and augmented assignment operators of different variable assignment lines in the same block.
For the case when there are two assignment operators on one line, only the first assignment operator is aligned:
New block starts with new alignment. There are 5 cases that are featured to indicate a new block:
If there is any blank line in between:
If there is any comment line in between:
If there is any if/ while/ for line or function definition def line in between:
If there is any object(e.g. a dictionary, a list, a argument list, a set, a function call) that with its items on newlines after '=' in between:
If there is any variable assignment lines with different indentation in between:
knob: ALIGN_ASSIGNMENT_RESTART_AFTER_COMMENTS
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.
format_token.py
: necessary boolean functions are added, is_assign, is_augassign.Finally
In the end, the knobs are added into the style.py and tests for each one are also updated in yapftests folder.
style.py
: all the 2 knobs are set to be False by default.reformatter_basic_test.py
.