@@ -1300,6 +1300,7 @@ def fix_e721(self, result):
13001300 # NOTE: match objects
13011301 # * type(a) == type(b) -> (None, None, 'a', '==')
13021302 # * str == type(b) -> ('==', 'b', None, None)
1303+ # * type(b) == str -> (None, None, 'b', '==')
13031304 # * type("") != type(b) -> (None, None, '""', '!=')
13041305 start = match .start ()
13051306 end = match .end ()
@@ -1320,6 +1321,10 @@ def fix_e721(self, result):
13201321 isinstance_stmt = " not isinstance"
13211322
13221323 _type_comp = f"{ _target_obj } , { target [:start ]} "
1324+ indent_match = re .match (r'^\s+' , target )
1325+ indent = ""
1326+ if indent_match :
1327+ indent = indent_match .group ()
13231328
13241329 _prefix_tmp = target [:start ].split ()
13251330 if len (_prefix_tmp ) >= 1 :
@@ -1332,15 +1337,28 @@ def fix_e721(self, result):
13321337
13331338 _suffix_tmp = target [end :]
13341339 _suffix_type_match = TYPE_REGEX .search (_suffix_tmp )
1335- if len ( _suffix_tmp . split ()) >= 1 and _suffix_type_match :
1336- if _suffix_type_match :
1340+ if _suffix_type_match :
1341+ if len ( _suffix_tmp . split ()) >= 1 :
13371342 type_match_end = _suffix_type_match .end ()
13381343 _suffix = _suffix_tmp [type_match_end :]
1339- if _suffix_type_match :
13401344 cmp_b = _suffix_type_match .groups ()[0 ]
13411345 _type_comp = f"{ _target_obj } , { cmp_b } "
1342-
1343- fix_line = f"{ _prefix } { isinstance_stmt } ({ _type_comp } ){ _suffix } "
1346+ else :
1347+ _else_suffix_match = re .match (
1348+ r"^\s*([^\s:]+)(.*)$" ,
1349+ _suffix_tmp ,
1350+ )
1351+ if _else_suffix_match :
1352+ _else_suffix = _else_suffix_match .group (1 )
1353+ _else_suffix_other = _else_suffix_match .group (2 )
1354+ _type_comp = f"{ _target_obj } , { _else_suffix } "
1355+ _else_suffix_end = _suffix_tmp [_else_suffix_match .end ():]
1356+ _suffix = f"{ _else_suffix_other } { _else_suffix_end } "
1357+ # `else` route is not care
1358+
1359+ fix_line = (
1360+ f"{ indent } { _prefix } { isinstance_stmt } ({ _type_comp } ){ _suffix } "
1361+ )
13441362 self .source [line_index ] = fix_line
13451363
13461364 def fix_e722 (self , result ):
0 commit comments