From 765402a0289dd4f3f8a7b56c9e36e33f77fe656b Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Wed, 29 May 2024 08:41:21 +0900 Subject: [PATCH] fix: check just before fixed-method --- autopep8.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/autopep8.py b/autopep8.py index da86c58e..437c92f7 100755 --- a/autopep8.py +++ b/autopep8.py @@ -529,6 +529,13 @@ def __init__(self, filename, self.fix_w292 = self.fix_w291 self.fix_w293 = self.fix_w291 + def _check_affected_anothers(self, result) -> bool: + """Check if the fix affects the number of lines of another remark.""" + line_index = result['line'] - 1 + target = self.source[line_index] + original_target = self.original_source[line_index] + return target != original_target + def _fix_source(self, results): try: (logical_start, logical_end) = _find_logical(self.source) @@ -541,14 +548,6 @@ def _fix_source(self, results): if result['line'] in completed_lines: continue - # NOTE: Skip if the correction by the fixed-method affects - # the number of lines of another remark. - _line_index = result['line'] - 1 - _target = self.source[_line_index] - _original_target = self.original_source[_line_index] - if _target != _original_target: - continue - fixed_methodname = 'fix_' + result['id'].lower() if hasattr(self, fixed_methodname): fix = getattr(self, fixed_methodname) @@ -570,8 +569,12 @@ def _fix_source(self, results): completed_lines): continue + if self._check_affected_anothers(result): + continue modified_lines = fix(result, logical) else: + if self._check_affected_anothers(result): + continue modified_lines = fix(result) if modified_lines is None: