1
+ import functools
1
2
import importlib .util
2
3
3
4
from libcst import FlattenSentinel , RemoveFromParent , matchers
@@ -57,7 +58,7 @@ def __init__(self, context, flag_name, flag_resolution_methods, ignored_module_c
57
58
58
59
self .flag_resolution_matcher = matchers .Call (
59
60
func = matchers .Name (self .method_resolution_name ),
60
- args = matchers .MatchIfTrue (lambda a : matchers . matches ( a [ 0 ]. value , matchers . Name ( self .flag_name ) )),
61
+ args = matchers .MatchIfTrue (functools . partial ( _matches_flag_name , self .flag_name )),
61
62
)
62
63
63
64
def visit_Module (self , node ):
@@ -66,7 +67,7 @@ def visit_Module(self, node):
66
67
def leave_Module (self , original_node , updated_node ):
67
68
self .flag_resolution_matcher = matchers .Call (
68
69
func = matchers .Name (self .method_resolution_name ),
69
- args = matchers .MatchIfTrue (lambda a : matchers . matches ( a [ 0 ]. value , matchers . Name ( self .flag_name ) )),
70
+ args = matchers .MatchIfTrue (functools . partial ( _matches_flag_name , self .flag_name )),
70
71
)
71
72
72
73
return updated_node
@@ -76,7 +77,7 @@ def leave_ImportFrom(self, original_node, updated_node):
76
77
if aliased_flag_name is not None :
77
78
self .flag_resolution_matcher = matchers .Call (
78
79
func = matchers .Name (self .method_resolution_name ),
79
- args = matchers .MatchIfTrue (lambda a : matchers . matches ( a [ 0 ]. value , matchers . Name ( aliased_flag_name ) )),
80
+ args = matchers .MatchIfTrue (functools . partial ( _matches_flag_name , aliased_flag_name )),
80
81
)
81
82
82
83
imported_names_after_removing_flag = [
@@ -95,7 +96,7 @@ def leave_Import(self, original_node, updated_node):
95
96
aliased_flag_name = flag_imports_nodes [0 ].asname .name .value
96
97
self .flag_resolution_matcher = matchers .Call (
97
98
func = matchers .Name (self .method_resolution_name ),
98
- args = matchers .MatchIfTrue (lambda a : matchers . matches ( a [ 0 ]. value , matchers . Name ( aliased_flag_name ) )),
99
+ args = matchers .MatchIfTrue (functools . partial ( _matches_flag_name , aliased_flag_name )),
99
100
)
100
101
101
102
imported_names_after_removing_flag = [
@@ -196,6 +197,10 @@ def _updated_tuple_assignment(self, updated_node):
196
197
)
197
198
198
199
200
+ def _matches_flag_name (flag_name , n ):
201
+ return matchers .matches (n [0 ].value , matchers .Name (flag_name ))
202
+
203
+
199
204
def _is_tuple_assignment (updated_node ):
200
205
return len (updated_node .targets ) == 1 and matchers .matches (
201
206
updated_node .targets [0 ].target , matchers .TypeOf (matchers .Tuple )
0 commit comments