11import abc
2- from typing import Callable , Generic , Mapping , Sequence , Set , TypeVar , Union
2+ from typing import Generic , Mapping , Sequence , Set , TypeVar , Union
33
44import libcst as cst
55from libcst import matchers
66from libcst .codemod import CodemodContext , VisitorBasedCodemodCommand
7- from libcst .metadata import PositionProvider
8- from typing_extensions import override
7+ from libcst .metadata import ParentNodeProvider , PositionProvider
98
109from codemodder .codemods .base_visitor import UtilsMixin
1110from codemodder .codemods .utils_mixin import NameResolutionMixin
@@ -24,7 +23,7 @@ class ImportedCallModifier(
2423 UtilsMixin ,
2524 metaclass = abc .ABCMeta ,
2625):
27- METADATA_DEPENDENCIES = (PositionProvider , )
26+ METADATA_DEPENDENCIES = (ParentNodeProvider , PositionProvider )
2827
2928 def __init__ (
3029 self ,
@@ -33,7 +32,6 @@ def __init__(
3332 matching_functions : FunctionMatchType ,
3433 change_description : str ,
3534 results : list [Result ] | None = None ,
36- result_filter : Callable [[cst .CSTNode ], bool ] | None = None ,
3735 ):
3836 VisitorBasedCodemodCommand .__init__ (self , codemod_context )
3937 self .line_exclude = file_context .line_exclude
@@ -43,15 +41,6 @@ def __init__(
4341 self .changes_in_file : list [Change ] = []
4442 self .results = results
4543 self .file_context = file_context
46- self .result_filter = result_filter
47-
48- @override
49- def filter_by_result (self , node : cst .CSTNode ) -> bool :
50- return (
51- self .result_filter (node )
52- if self .result_filter
53- else super ().filter_by_result (node )
54- )
5544
5645 def updated_args (self , original_args : Sequence [cst .Arg ]):
5746 return original_args
@@ -82,7 +71,7 @@ def leave_Call(self, original_node: cst.Call, updated_node: cst.Call):
8271 if self .filter_by_path_includes_or_excludes (pos_to_match ):
8372 true_name = self .find_base_name (original_node .func )
8473 if (
85- self ._is_direct_call_from_imported_module (original_node )
74+ self .is_direct_call_from_imported_module (original_node )
8675 and true_name
8776 and true_name in self .matching_functions
8877 ):
0 commit comments