Skip to content

Commit

Permalink
impl: e721 fixed method
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed Mar 17, 2024
1 parent b84b8a2 commit 328b352
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class documentation for more information.
from configparser import ConfigParser as SafeConfigParser, Error

import pycodestyle
from pycodestyle import STARTSWITH_INDENT_STATEMENT_REGEX
from pycodestyle import STARTSWITH_INDENT_STATEMENT_REGEX, COMPARE_TYPE_REGEX


__version__ = '2.0.4'
Expand Down Expand Up @@ -444,7 +444,7 @@ class FixPEP8(object):
- e502
- e701,e702,e703,e704
- e711,e712,e713,e714
- e722
- e721,e722
- e731
- w291
- w503,504
Expand Down Expand Up @@ -1257,6 +1257,24 @@ def fix_e714(self, result):
new_target[:pos_start], 'is not', new_target[pos_end:])
self.source[line_index] = new_target

def fix_e721(self, result):
"""fix comparison type"""
(line_index, _, target) = get_index_offset_contents(result,
self.source)
match = COMPARE_TYPE_REGEX.search(target)
if match:
start = match.start()
end = match.end()
_prefix = ""
_type_comp = f"{match.groups()[0]}, {target[:start]}"
_tmp = target[:start].split()
if len(_tmp) >= 2:
_type_comp = f"{match.groups()[0]}, {_tmp[-1]}"
_prefix = "".join(_tmp[:-1])

fix_line = f"{_prefix} isinstance({_type_comp}){target[end:]}"
self.source[line_index] = fix_line

def fix_e722(self, result):
"""fix bare except"""
(line_index, _, target) = get_index_offset_contents(result,
Expand Down

0 comments on commit 328b352

Please sign in to comment.