1717from astroid .inference_tip import inference_tip
1818from astroid .interpreter import objectmodel
1919from astroid .manager import AstroidManager
20- from astroid .nodes .node_classes import AssignName , Attribute , Call , Name
21- from astroid .nodes .scoped_nodes import FunctionDef
2220from astroid .typing import InferenceResult , SuccessfulInferenceResult
2321from astroid .util import UninferableBase , safe_infer
2422
@@ -92,7 +90,7 @@ def _functools_partial_inference(
9290 raise UseInferenceDefault from exc
9391 if isinstance (inferred_wrapped_function , UninferableBase ):
9492 raise UseInferenceDefault ("Cannot infer the wrapped function" )
95- if not isinstance (inferred_wrapped_function , FunctionDef ):
93+ if not isinstance (inferred_wrapped_function , nodes . FunctionDef ):
9694 raise UseInferenceDefault ("The wrapped function is not a function" )
9795
9896 # Determine if the passed keywords into the callsite are supported
@@ -106,7 +104,9 @@ def _functools_partial_inference(
106104 inferred_wrapped_function .args .kwonlyargs or (),
107105 )
108106 parameter_names = {
109- param .name for param in function_parameters if isinstance (param , AssignName )
107+ param .name
108+ for param in function_parameters
109+ if isinstance (param , nodes .AssignName )
110110 }
111111 if set (call .keyword_arguments ) - parameter_names :
112112 raise UseInferenceDefault ("wrapped function received unknown parameters" )
@@ -135,23 +135,25 @@ def _looks_like_lru_cache(node) -> bool:
135135 if not node .decorators :
136136 return False
137137 for decorator in node .decorators .nodes :
138- if not isinstance (decorator , (Attribute , Call )):
138+ if not isinstance (decorator , (nodes . Attribute , nodes . Call )):
139139 continue
140140 if _looks_like_functools_member (decorator , "lru_cache" ):
141141 return True
142142 return False
143143
144144
145- def _looks_like_functools_member (node : Attribute | Call , member : str ) -> bool :
145+ def _looks_like_functools_member (
146+ node : nodes .Attribute | nodes .Call , member : str
147+ ) -> bool :
146148 """Check if the given Call node is the wanted member of functools."""
147- if isinstance (node , Attribute ):
149+ if isinstance (node , nodes . Attribute ):
148150 return node .attrname == member
149- if isinstance (node .func , Name ):
151+ if isinstance (node .func , nodes . Name ):
150152 return node .func .name == member
151- if isinstance (node .func , Attribute ):
153+ if isinstance (node .func , nodes . Attribute ):
152154 return (
153155 node .func .attrname == member
154- and isinstance (node .func .expr , Name )
156+ and isinstance (node .func .expr , nodes . Name )
155157 and node .func .expr .name == "functools"
156158 )
157159 return False
@@ -161,10 +163,12 @@ def _looks_like_functools_member(node: Attribute | Call, member: str) -> bool:
161163
162164
163165def register (manager : AstroidManager ) -> None :
164- manager .register_transform (FunctionDef , _transform_lru_cache , _looks_like_lru_cache )
166+ manager .register_transform (
167+ nodes .FunctionDef , _transform_lru_cache , _looks_like_lru_cache
168+ )
165169
166170 manager .register_transform (
167- Call ,
171+ nodes . Call ,
168172 inference_tip (_functools_partial_inference ),
169173 _looks_like_partial ,
170174 )
0 commit comments