1515
1616_SEPARATOR_PATTERN = re .compile (r"[.:]|::" )
1717_CHAINED_METHOD_PATTERN = re .compile (r"\.([^.()]+)$" )
18- _JS_INSTANCE_PREFIXES = {cs .KEYWORD_SELF , "this" }
1918
2019
2120class CallResolver :
@@ -53,15 +52,6 @@ def _try_resolve_method(
5352 method_qn = f"{ class_qn } { separator } { method_name } "
5453 if method_qn in self .function_registry :
5554 return self .function_registry [method_qn ], method_qn
56-
57- class_name = class_qn .split (cs .SEPARATOR_DOT )[- 1 ]
58- suffix_matches = self .function_registry .find_ending_with (
59- f"{ class_name } { separator } { method_name } "
60- )
61- if len (suffix_matches ) == 1 :
62- matched_qn = suffix_matches [0 ]
63- return self .function_registry [matched_qn ], matched_qn
64-
6555 return self ._resolve_inherited_method (class_qn , method_name )
6656
6757 def resolve_function_call (
@@ -81,17 +71,14 @@ def resolve_function_call(
8171 return self ._resolve_chained_call (call_name , module_qn , local_var_types )
8272
8373 if result := self ._try_resolve_via_imports (
84- call_name , module_qn , local_var_types , class_context
74+ call_name , module_qn , local_var_types
8575 ):
8676 return result
8777
88- if not self ._has_separator (call_name ):
89- if result := self ._try_resolve_same_module (call_name , module_qn ):
90- return result
91- return self ._try_resolve_via_trie (call_name , module_qn )
78+ if result := self ._try_resolve_same_module (call_name , module_qn ):
79+ return result
9280
93- logger .debug (ls .CALL_UNRESOLVED , call_name = call_name )
94- return None
81+ return self ._try_resolve_via_trie (call_name , module_qn )
9582
9683 def _try_resolve_iife (
9784 self , call_name : str , module_qn : str
@@ -120,21 +107,21 @@ def _try_resolve_via_imports(
120107 call_name : str ,
121108 module_qn : str ,
122109 local_var_types : dict [str , str ] | None ,
123- class_context : str | None = None ,
124110 ) -> tuple [str , str ] | None :
125- import_map = self .import_processor .import_mapping .get (module_qn , {})
111+ if module_qn not in self .import_processor .import_mapping :
112+ return None
113+
114+ import_map = self .import_processor .import_mapping [module_qn ]
126115
127116 if result := self ._try_resolve_direct_import (call_name , import_map ):
128117 return result
129118
130119 if result := self ._try_resolve_qualified_call (
131- call_name , import_map , module_qn , local_var_types , class_context
120+ call_name , import_map , module_qn , local_var_types
132121 ):
133122 return result
134123
135- if import_map :
136- return self ._try_resolve_wildcard_imports (call_name , import_map )
137- return None
124+ return self ._try_resolve_wildcard_imports (call_name , import_map )
138125
139126 def _try_resolve_direct_import (
140127 self , call_name : str , import_map : dict [str , str ]
@@ -153,7 +140,6 @@ def _try_resolve_qualified_call(
153140 import_map : dict [str , str ],
154141 module_qn : str ,
155142 local_var_types : dict [str , str ] | None ,
156- class_context : str | None = None ,
157143 ) -> tuple [str , str ] | None :
158144 if not self ._has_separator (call_name ):
159145 return None
@@ -163,17 +149,11 @@ def _try_resolve_qualified_call(
163149
164150 if len (parts ) == 2 :
165151 if result := self ._resolve_two_part_call (
166- parts ,
167- call_name ,
168- separator ,
169- import_map ,
170- module_qn ,
171- local_var_types ,
172- class_context ,
152+ parts , call_name , separator , import_map , module_qn , local_var_types
173153 ):
174154 return result
175155
176- if len (parts ) >= 3 and parts [0 ] in _JS_INSTANCE_PREFIXES :
156+ if len (parts ) >= 3 and parts [0 ] == cs . KEYWORD_SELF :
177157 return self ._resolve_self_attribute_call (
178158 parts , call_name , import_map , module_qn , local_var_types
179159 )
@@ -255,14 +235,9 @@ def _resolve_two_part_call(
255235 import_map : dict [str , str ],
256236 module_qn : str ,
257237 local_var_types : dict [str , str ] | None ,
258- class_context : str | None = None ,
259238 ) -> tuple [str , str ] | None :
260239 object_name , method_name = parts
261240
262- if object_name in _JS_INSTANCE_PREFIXES and class_context :
263- if result := self ._try_resolve_method (class_context , method_name , separator ):
264- return result
265-
266241 if result := self ._try_resolve_via_local_type (
267242 object_name ,
268243 method_name ,
@@ -279,7 +254,7 @@ def _resolve_two_part_call(
279254 ):
280255 return result
281256
282- return None
257+ return self . _try_resolve_module_method ( method_name , call_name , module_qn )
283258
284259 def _try_resolve_via_local_type (
285260 self ,
@@ -426,15 +401,28 @@ def _resolve_self_attribute_call(
426401 if class_qn := self ._resolve_class_qn_from_type (
427402 var_type , import_map , module_qn
428403 ):
429- if resolved_method := self ._try_resolve_method (class_qn , method_name ):
404+ method_qn = f"{ class_qn } .{ method_name } "
405+ if method_qn in self .function_registry :
430406 logger .debug (
431407 ls .CALL_INSTANCE_ATTR ,
432408 call_name = call_name ,
433- method_qn = resolved_method [ 1 ] ,
409+ method_qn = method_qn ,
434410 attr_ref = attribute_ref ,
435411 var_type = var_type ,
436412 )
437- return resolved_method
413+ return self .function_registry [method_qn ], method_qn
414+
415+ if inherited_method := self ._resolve_inherited_method (
416+ class_qn , method_name
417+ ):
418+ logger .debug (
419+ ls .CALL_INSTANCE_ATTR_INHERITED ,
420+ call_name = call_name ,
421+ method_qn = inherited_method [1 ],
422+ attr_ref = attribute_ref ,
423+ var_type = var_type ,
424+ )
425+ return inherited_method
438426
439427 return None
440428
0 commit comments