From e1e28c2f7640b60e20e20087aae309de2100f95b Mon Sep 17 00:00:00 2001 From: Xiao Wang Date: Thu, 18 Aug 2022 17:03:58 +0200 Subject: [PATCH 1/3] update the two fixes --- yapf/yapflib/reformatter.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/yapf/yapflib/reformatter.py b/yapf/yapflib/reformatter.py index 14e0bde70..7137d4044 100644 --- a/yapf/yapflib/reformatter.py +++ b/yapf/yapflib/reformatter.py @@ -321,7 +321,7 @@ def _AlignTrailingComments(final_lines): if line_tok.is_comment: pc_line_lengths.append(len(line_content)) - else: + elif not line_tok.is_pseudo: line_content += '{}{}'.format(whitespace_prefix, line_tok.value) if pc_line_lengths: @@ -361,15 +361,18 @@ def _AlignTrailingComments(final_lines): aligned_col - pc_line_lengths[pc_line_length_index] - 1) pc_line_length_index += 1 - line_content = [] + print('line_tok:', len(line_tok.formatted_whitespace_prefix.lstrip('\n'))) + print('padded spaces:', len(whitespace)) + line_content = [] + padded_space = whitespace for comment_line_index, comment_line in enumerate( line_tok.value.split('\n')): - line_content.append('{}{}'.format(whitespace, + line_content.append('{}{}'.format(padded_space, comment_line.strip())) if comment_line_index == 0: - whitespace = ' ' * (aligned_col - 1) + padded_space = ' ' * (aligned_col - 1) line_content = '\n'.join(line_content) @@ -378,7 +381,12 @@ def _AlignTrailingComments(final_lines): existing_whitespace_prefix = \ line_tok.formatted_whitespace_prefix.lstrip('\n') - if line_content.startswith(existing_whitespace_prefix): + # In case that the existing spaces larger than + # spaces that needed to pad, set the whitespace_prefix to empty + if len(existing_whitespace_prefix)>len(whitespace): + line_tok.whitespace_prefix = '' + + elif line_content.startswith(existing_whitespace_prefix): line_content = line_content[len(existing_whitespace_prefix):] line_tok.value = line_content From 316c65af38e3886532f6a3ec6eedd9f223cbbfa9 Mon Sep 17 00:00:00 2001 From: Xiao Wang Date: Tue, 30 Aug 2022 12:28:29 +0200 Subject: [PATCH 2/3] update changelog --- CHANGELOG | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5ac3e6329..92300bd19 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,13 @@ # All notable changes to this project will be documented in this file. # This project adheres to [Semantic Versioning](http://semver.org/). +## [0.40.2] 2022-08-30 +### Fixed +- Fixed a problem in _AlignTrailingComments(final_lines). + Exclude the pseudo parantheses when calculating the line length before the comment. +- Fixed another problem when the number of the existing spaces before the + comment is larger than the padding spaces needed to align. + ## [0.40.0] UNRELEASED ### Added - Add a new Python parser to generate logical lines. From 022651fdbe9736744dd9fdec602ad8338d7c53e6 Mon Sep 17 00:00:00 2001 From: Xiao Wang Date: Tue, 30 Aug 2022 12:57:13 +0200 Subject: [PATCH 3/3] fix typos and delete print lines --- CHANGELOG | 2 +- yapf/yapflib/reformatter.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 92300bd19..13b030231 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,7 @@ # All notable changes to this project will be documented in this file. # This project adheres to [Semantic Versioning](http://semver.org/). -## [0.40.2] 2022-08-30 +## [0.41.2] 2022-08-30 ### Fixed - Fixed a problem in _AlignTrailingComments(final_lines). Exclude the pseudo parantheses when calculating the line length before the comment. diff --git a/yapf/yapflib/reformatter.py b/yapf/yapflib/reformatter.py index 7137d4044..c0530c935 100644 --- a/yapf/yapflib/reformatter.py +++ b/yapf/yapflib/reformatter.py @@ -361,9 +361,6 @@ def _AlignTrailingComments(final_lines): aligned_col - pc_line_lengths[pc_line_length_index] - 1) pc_line_length_index += 1 - print('line_tok:', len(line_tok.formatted_whitespace_prefix.lstrip('\n'))) - print('padded spaces:', len(whitespace)) - line_content = [] padded_space = whitespace for comment_line_index, comment_line in enumerate(