Feature align assignment (continued)#1280
Closed
Andrea-Oliveri wants to merge 853 commits intogoogle:mainfrom
Closed
Feature align assignment (continued)#1280Andrea-Oliveri wants to merge 853 commits intogoogle:mainfrom
Andrea-Oliveri wants to merge 853 commits intogoogle:mainfrom
Conversation
"... split such that all elements are on a single line." could be interpreted to mean that all elements will be combined into a single line, but the knob really means that each element will appear on a separate line.
* support ignore config in pyproject.toml * add doc in readme * add tests * changelog
Replace if statement with if expression
Replace multiple comparisons with in operator
…ngle blank line (#954) * PEP8: Method definitions inside a class are surrounded by a single blank line. * Add changelog entry for "pep8" style update
* [RFC] Added yapf_api.FormatTree The new entry point allows to avoid re-parsing when a lib2to3 pytree has already been constructed. Closes #951. * Updated CHANGELOG * Fix spacing Co-authored-by: Bill Wendling <5993918+gwelymernans@users.noreply.github.com>
Don't rely upon the original "pytree node" object. This helps isolate the lib2to3 objects from yapf.
Grammer correction
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.1 to 4.1.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@b4ffde6...9bb5618) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
….2 (#1213) Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 6.0.0 to 6.0.2. - [Release notes](https://github.com/peter-evans/create-pull-request/releases) - [Commits](peter-evans/create-pull-request@b1ddad2...70a41ab) --- updated-dependencies: - dependency-name: peter-evans/create-pull-request dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 5.0.0 to 5.1.0. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](actions/setup-python@0a5c615...82c7e63) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* ci.yml: Disable "fail fast" .. to better see if failure depends on architecture and/or Python version only * ci.yml: Stop CI from trying Python 3.7 on arm64 macOS Symptom was this error: > Error: The version '3.7' with architecture 'arm64' was not found for macOS 14.6.1. > The list of all available versions can be found here: https://raw.githubusercontent.com/actions/python-versions/main/versions-manifest.json Note that Python 3.7 is end-of life since 2023-06-27.
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.1.2 to 4.2.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@9bb5618...d632683) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…r.load (#1243) Previously, bad timing could make another process run into reading a half-written pickle cache file, and thus fail like this: > Traceback (most recent call last): > File "[..]/bin/yapf", line 5, in <module> > from yapf import run_main > File "[..]/lib/python3.11/site-packages/yapf/__init__.py", line 41, in <module> > from yapf.yapflib import yapf_api > File "[..]/lib/python3.11/site-packages/yapf/yapflib/yapf_api.py", line 38, in <module> > from yapf.pyparser import pyparser > File "[..]/lib/python3.11/site-packages/yapf/pyparser/pyparser.py", line 44, in <module> > from yapf.yapflib import format_token > File "[..]/lib/python3.11/site-packages/yapf/yapflib/format_token.py", line 23, in <module> > from yapf.pytree import pytree_utils > File "[..]/lib/python3.11/site-packages/yapf/pytree/pytree_utils.py", line 30, in <module> > from yapf_third_party._ylib2to3 import pygram > File "[..]/lib/python3.11/site-packages/yapf_third_party/_ylib2to3/pygram.py", line 29, in <module> > python_grammar = driver.load_grammar(_GRAMMAR_FILE) > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ > File "[..]/lib/python3.11/site-packages/yapf_third_party/_ylib2to3/pgen2/driver.py", line 252, in load_grammar > g.load(gp) > File "[..]/lib/python3.11/site-packages/yapf_third_party/_ylib2to3/pgen2/grammar.py", line 95, in load > d = pickle.load(f) > ^^^^^^^^^^^^^^ > EOFError: Ran out of input
….5 (#1239) Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 6.0.2 to 7.0.5. - [Release notes](https://github.com/peter-evans/create-pull-request/releases) - [Commits](peter-evans/create-pull-request@70a41ab...5e91468) --- updated-dependencies: - dependency-name: peter-evans/create-pull-request dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/checkout](https://github.com/actions/checkout) from 4.2.0 to 4.2.1. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@d632683...eef6144) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: pre-commit <pre-commit@tools.invalid>
Co-authored-by: pre-commit <pre-commit@tools.invalid>
… with FormatToken.is_arithmetic_op
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
Apologies, apparently I spelled incorrectly my email which causes cla check to fail. I will put in draft until solved. |
1b636a8 to
53f2f5f
Compare
Author
|
I broke the history. Will try different approach to solve wrong email and open a new PR. Apologies |
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_COMMENTLINEtoALIGN_ASSIGNMENT_RESTART_AFTER_COMMENTS, as recommended._AlignAssignmentinto multiple smaller functions._AlignAssignmentwas heavily, heavily inspired from_AlignTrailingComments, I decided to group the common logic into a single generic function which takes callbacks for the specific tasks._AlignTrailingCommentsto its previous state and we can keep duplicated logic.mainbranch.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.