@@ -100,10 +100,9 @@ def strip_line_label(line: str) -> tuple[str, str | None]:
100100 match = FRegex .LINE_LABEL .match (line )
101101 if match is None :
102102 return line , None
103- else :
104- line_label = match .group (1 )
105- out_str = line [: match .start (1 )] + " " * len (line_label ) + line [match .end (1 ) :]
106- return out_str , line_label
103+ line_label = match .group (1 )
104+ out_str = line [: match .start (1 )] + " " * len (line_label ) + line [match .end (1 ) :]
105+ return out_str , line_label
107106
108107
109108def strip_strings (in_line : str , maintain_len : bool = False ) -> str :
@@ -172,7 +171,7 @@ def separate_def_list(test_str: str) -> list[str] | None:
172171 if curr_str != "" :
173172 def_list .append (curr_str )
174173 curr_str = ""
175- elif ( curr_str == "" ) and ( len ( def_list ) == 0 ) :
174+ elif not def_list :
176175 return None
177176 continue
178177 curr_str += char
@@ -198,17 +197,20 @@ def find_word_in_line(line: str, word: str) -> Range:
198197 start and end positions (indices) of the word if not found it returns
199198 -1, len(word) -1
200199 """
201- i = - 1
202- for poss_name in FRegex .WORD .finditer (line ):
203- if poss_name .group () == word :
204- i = poss_name .start ()
205- break
200+ i = next (
201+ (
202+ poss_name .start ()
203+ for poss_name in FRegex .WORD .finditer (line )
204+ if poss_name .group () == word
205+ ),
206+ - 1 ,
207+ )
206208 # TODO: if i == -1: return None makes more sense
207209 return Range (i , i + len (word ))
208210
209211
210212def find_paren_match (string : str ) -> int :
211- """Find matching closing parenthesis ** from an already open parenthesis scope**
213+ """Find matching closing parenthesis from an already open parenthesis scope
212214 by forward search of the string, returns -1 if no match is found
213215
214216 Parameters
@@ -237,15 +239,14 @@ def find_paren_match(string: str) -> int:
237239 -1
238240 """
239241 paren_count = 1
240- ind = - 1
241242 for i , char in enumerate (string ):
242243 if char == "(" :
243244 paren_count += 1
244245 elif char == ")" :
245246 paren_count -= 1
246247 if paren_count == 0 :
247248 return i
248- return ind
249+ return - 1
249250
250251
251252def get_line_prefix (
@@ -282,17 +283,16 @@ def get_line_prefix(
282283 col += len (prepend_string )
283284 line_prefix = curr_line [:col ].lower ()
284285 # Ignore string literals
285- if qs :
286- if (line_prefix .find ("'" ) > - 1 ) or (line_prefix .find ('"' ) > - 1 ):
287- sq_count = 0
288- dq_count = 0
289- for char in line_prefix :
290- if (char == "'" ) and (dq_count % 2 == 0 ):
291- sq_count += 1
292- elif (char == '"' ) and (sq_count % 2 == 0 ):
293- dq_count += 1
294- if (dq_count % 2 == 1 ) or (sq_count % 2 == 1 ):
295- return None
286+ if qs and ((line_prefix .find ("'" ) > - 1 ) or (line_prefix .find ('"' ) > - 1 )):
287+ sq_count = 0
288+ dq_count = 0
289+ for char in line_prefix :
290+ if (char == "'" ) and (dq_count % 2 == 0 ):
291+ sq_count += 1
292+ elif (char == '"' ) and (sq_count % 2 == 0 ):
293+ dq_count += 1
294+ if (dq_count % 2 == 1 ) or (sq_count % 2 == 1 ):
295+ return None
296296 return line_prefix
297297
298298
@@ -329,14 +329,12 @@ def resolve_globs(glob_path: str, root_path: str = None) -> list[str]:
329329 >>> resolve_globs('test') == [str(pathlib.Path(os.getcwd()) / 'test')]
330330 True
331331 """
332- # Resolve absolute paths i.e. not in our root_path
333- if os .path .isabs (glob_path ) or not root_path :
334- p = Path (glob_path ).resolve ()
335- root = p .anchor # drive letter + root path
336- rel = str (p .relative_to (root )) # contains glob pattern
337- return [str (p .resolve ()) for p in Path (root ).glob (rel )]
338- else :
332+ if not os .path .isabs (glob_path ) and root_path :
339333 return [str (p .resolve ()) for p in Path (root_path ).resolve ().glob (glob_path )]
334+ p = Path (glob_path ).resolve ()
335+ root = p .anchor # drive letter + root path
336+ rel = str (p .relative_to (root )) # contains glob pattern
337+ return [str (p .resolve ()) for p in Path (root ).glob (rel )]
340338
341339
342340def only_dirs (paths : list [str ]) -> list [str ]:
@@ -406,7 +404,9 @@ def map_keywords(keywords: list[str]):
406404 return mapped_keywords , keyword_info
407405
408406
409- def get_keywords (keywords : list , keyword_info : dict = {}):
407+ def get_keywords (keywords : list , keyword_info : dict = None ):
408+ if keyword_info is None :
409+ keyword_info = {}
410410 keyword_strings = []
411411 for keyword_id in keywords :
412412 string_rep = KEYWORD_LIST [keyword_id ]
@@ -461,10 +461,7 @@ def get_paren_substring(string: str) -> str | None:
461461 """
462462 i1 = string .find ("(" )
463463 i2 = string .rfind (")" )
464- if - 1 < i1 < i2 :
465- return string [i1 + 1 : i2 ]
466- else :
467- return None
464+ return string [i1 + 1 : i2 ] if - 1 < i1 < i2 else None
468465
469466
470467def get_paren_level (line : str ) -> tuple [str , list [Range ]]:
@@ -496,7 +493,7 @@ def get_paren_level(line: str) -> tuple[str, list[Range]]:
496493 ('', [Range(start=0, end=0)])
497494
498495 """
499- if line == "" :
496+ if not line :
500497 return "" , [Range (0 , 0 )]
501498 level = 0
502499 in_string = False
@@ -526,9 +523,7 @@ def get_paren_level(line: str) -> tuple[str, list[Range]]:
526523 if level == 0 :
527524 sections .append (Range (i , i1 ))
528525 sections .reverse ()
529- out_string = ""
530- for section in sections :
531- out_string += line [section .start : section .end ]
526+ out_string = "" .join (line [section .start : section .end ] for section in sections )
532527 return out_string , sections
533528
534529
@@ -564,7 +559,7 @@ def get_var_stack(line: str) -> list[str]:
564559 >>> get_var_stack('')
565560 ['']
566561 """
567- if len ( line ) == 0 :
562+ if not line :
568563 return ["" ]
569564 final_var , sections = get_paren_level (line )
570565 if final_var == "" :
@@ -574,10 +569,9 @@ def get_var_stack(line: str) -> list[str]:
574569 for i , section in enumerate (sections ):
575570 if not line [section .start : section .end ].strip ().startswith ("%" ):
576571 iLast = i
577- final_var = ""
578- for section in sections [iLast :]:
579- final_var += line [section .start : section .end ]
580-
572+ final_var = "" .join (
573+ line [section .start : section .end ] for section in sections [iLast :]
574+ )
581575 if final_var is not None :
582576 final_var = "%" .join ([i .strip () for i in final_var .split ("%" )])
583577 final_op_split : list [str ] = FRegex .OBJBREAK .split (final_var )
0 commit comments