88from collections import defaultdict
99from functools import cache
1010from pathlib import Path
11- from typing import TYPE_CHECKING , Any , Optional , Tuple
11+ from typing import TYPE_CHECKING , Any , Optional
1212
1313import git
1414import libcst as cst
@@ -269,15 +269,16 @@ def get_functions_within_git_diff(uncommitted_changes: bool) -> dict[str, list[F
269269
270270def closest_matching_file_function_name (
271271 qualified_fn_to_find : str , found_fns : dict [Path , list [FunctionToOptimize ]]
272- ) -> Tuple [Path , FunctionToOptimize ] | None :
273- """Find closest matching function name using Levenshtein distance.
272+ ) -> tuple [Path , FunctionToOptimize ] | None :
273+ """Find the closest matching function name using Levenshtein distance.
274274
275275 Args:
276276 qualified_fn_to_find: Function name to find in format "Class.function" or "function"
277277 found_fns: Dictionary of file paths to list of functions
278278
279279 Returns:
280280 Tuple of (file_path, function) for closest match, or None if no matches found
281+
281282 """
282283 min_distance = 4
283284 closest_match = None
@@ -301,18 +302,18 @@ def closest_matching_file_function_name(
301302 return None
302303
303304
304- def levenshtein_distance (s1 : str , s2 : str ):
305+ def levenshtein_distance (s1 : str , s2 : str ) -> int :
305306 if len (s1 ) > len (s2 ):
306307 s1 , s2 = s2 , s1
307308 distances = range (len (s1 ) + 1 )
308309 for index2 , char2 in enumerate (s2 ):
309- newDistances = [index2 + 1 ]
310+ new_distances = [index2 + 1 ]
310311 for index1 , char1 in enumerate (s1 ):
311312 if char1 == char2 :
312- newDistances .append (distances [index1 ])
313+ new_distances .append (distances [index1 ])
313314 else :
314- newDistances .append (1 + min ((distances [index1 ], distances [index1 + 1 ], newDistances [- 1 ])))
315- distances = newDistances
315+ new_distances .append (1 + min ((distances [index1 ], distances [index1 + 1 ], new_distances [- 1 ])))
316+ distances = new_distances
316317 return distances [- 1 ]
317318
318319
0 commit comments