From a7ada1ff0272fd77206941cb6a7c4be9a53a995d Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Sun, 17 Mar 2024 13:05:37 +0900 Subject: [PATCH] fix: e721 --- autopep8.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/autopep8.py b/autopep8.py index 091f83e3..5df1a1bd 100755 --- a/autopep8.py +++ b/autopep8.py @@ -1266,13 +1266,21 @@ def fix_e721(self, result): start = match.start() end = match.end() _prefix = "" - _type_comp = f"{match.groups()[0]}, {target[:start]}" + if match.groups()[0] is None: + _target_obj = match.groups()[1] + else: + _target_obj = match.groups()[0] + + _type_comp = f"{_target_obj}, {target[:start]}" _tmp = target[:start].split() if len(_tmp) >= 2: - _type_comp = f"{match.groups()[0]}, {_tmp[-1]}" + _type_comp = f"{_target_obj}, {_tmp[-1]}" _prefix = "".join(_tmp[:-1]) - fix_line = f"{_prefix} isinstance({_type_comp}){target[end:]}" + if match.groups()[0] is None: + fix_line = f"{_prefix} isinstance({_type_comp}{target[end:-1]}){target[-1:]}" + else: + fix_line = f"{_prefix} isinstance({_type_comp}){target[end:]}" self.source[line_index] = fix_line def fix_e722(self, result):