Skip to content

Commit

Permalink
fix: e721
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Mar 17, 2024
1 parent 328b352 commit a7ada1f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a7ada1f

Please sign in to comment.