11from typing import cast , TypeVar , Union
22
3- from rewrite import SourceFile , TreeVisitor
4- from .extensions import *
3+ from rewrite import SourceFile , TreeVisitor , list_map
4+ from . import extensions
55from .support_types import *
66from .tree import *
77from rewrite .java import JavaVisitor
@@ -51,7 +51,7 @@ def visit_chained_assignment(self, chained_assignment: ChainedAssignment, p: P)
5151 return temp_statement
5252 chained_assignment = cast (ChainedAssignment , temp_statement )
5353 chained_assignment = chained_assignment .with_markers (self .visit_markers (chained_assignment .markers , p ))
54- chained_assignment = chained_assignment .padding .with_variables ([ self .visit_right_padded (v , PyRightPadded .Location .CHAINED_ASSIGNMENT_VARIABLES , p ) for v in chained_assignment .padding .variables ] )
54+ chained_assignment = chained_assignment .padding .with_variables (list_map ( lambda v : self .visit_right_padded (v , PyRightPadded .Location .CHAINED_ASSIGNMENT_VARIABLES , p ), chained_assignment .padding .variables ) )
5555 chained_assignment = chained_assignment .with_assignment (self .visit_and_cast (chained_assignment .assignment , Expression , p ))
5656 return chained_assignment
5757
@@ -92,8 +92,8 @@ def visit_type_hint(self, type_hint: TypeHint, p: P) -> J:
9292 def visit_compilation_unit (self , compilation_unit : CompilationUnit , p : P ) -> J :
9393 compilation_unit = compilation_unit .with_prefix (self .visit_space (compilation_unit .prefix , Space .Location .COMPILATION_UNIT_PREFIX , p ))
9494 compilation_unit = compilation_unit .with_markers (self .visit_markers (compilation_unit .markers , p ))
95- compilation_unit = compilation_unit .padding .with_imports ([ self .visit_right_padded (v , JRightPadded .Location .IMPORT , p ) for v in compilation_unit .padding .imports ] )
96- compilation_unit = compilation_unit .padding .with_statements ([ self .visit_right_padded (v , PyRightPadded .Location .COMPILATION_UNIT_STATEMENTS , p ) for v in compilation_unit .padding .statements ] )
95+ compilation_unit = compilation_unit .padding .with_imports (list_map ( lambda v : self .visit_right_padded (v , JRightPadded .Location .IMPORT , p ), compilation_unit .padding .imports ) )
96+ compilation_unit = compilation_unit .padding .with_statements (list_map ( lambda v : self .visit_right_padded (v , PyRightPadded .Location .COMPILATION_UNIT_STATEMENTS , p ), compilation_unit .padding .statements ) )
9797 compilation_unit = compilation_unit .with_eof (self .visit_space (compilation_unit .eof , Space .Location .COMPILATION_UNIT_EOF , p ))
9898 return compilation_unit
9999
@@ -180,7 +180,7 @@ def visit_formatted_string(self, formatted_string: FormattedString, p: P) -> J:
180180 return temp_expression
181181 formatted_string = cast (FormattedString , temp_expression )
182182 formatted_string = formatted_string .with_markers (self .visit_markers (formatted_string .markers , p ))
183- formatted_string = formatted_string .with_parts ([ self .visit_and_cast (v , Expression , p ) for v in formatted_string .parts ] )
183+ formatted_string = formatted_string .with_parts (list_map ( lambda v : self .visit_and_cast (v , Expression , p ), formatted_string .parts ) )
184184 return formatted_string
185185
186186 def visit_formatted_string_value (self , value : FormattedString .Value , p : P ) -> J :
@@ -223,7 +223,7 @@ def visit_comprehension_expression(self, comprehension_expression: Comprehension
223223 comprehension_expression = cast (ComprehensionExpression , temp_expression )
224224 comprehension_expression = comprehension_expression .with_markers (self .visit_markers (comprehension_expression .markers , p ))
225225 comprehension_expression = comprehension_expression .with_result (self .visit_and_cast (comprehension_expression .result , Expression , p ))
226- comprehension_expression = comprehension_expression .with_clauses ([ self .visit_and_cast (v , ComprehensionExpression .Clause , p ) for v in comprehension_expression .clauses ] )
226+ comprehension_expression = comprehension_expression .with_clauses (list_map ( lambda v : self .visit_and_cast (v , ComprehensionExpression .Clause , p ), comprehension_expression .clauses ) )
227227 comprehension_expression = comprehension_expression .with_suffix (self .visit_space (comprehension_expression .suffix , PySpace .Location .COMPREHENSION_EXPRESSION_SUFFIX , p ))
228228 return comprehension_expression
229229
@@ -239,7 +239,7 @@ def visit_comprehension_clause(self, clause: ComprehensionExpression.Clause, p:
239239 clause = clause .padding .with_async (self .visit_right_padded (clause .padding .async_ , PyRightPadded .Location .COMPREHENSION_EXPRESSION_CLAUSE_ASYNC , p ))
240240 clause = clause .with_iterator_variable (self .visit_and_cast (clause .iterator_variable , Expression , p ))
241241 clause = clause .padding .with_iterated_list (self .visit_left_padded (clause .padding .iterated_list , PyLeftPadded .Location .COMPREHENSION_EXPRESSION_CLAUSE_ITERATED_LIST , p ))
242- clause = clause .with_conditions ([ self .visit_and_cast (v , ComprehensionExpression .Condition , p ) for v in clause .conditions ] )
242+ clause = clause .with_conditions (list_map ( lambda v : self .visit_and_cast (v , ComprehensionExpression .Condition , p ), clause .conditions ) )
243243 return clause
244244
245245 def visit_type_alias (self , type_alias : TypeAlias , p : P ) -> J :
@@ -270,7 +270,7 @@ def visit_union_type(self, union_type: UnionType, p: P) -> J:
270270 return temp_expression
271271 union_type = cast (UnionType , temp_expression )
272272 union_type = union_type .with_markers (self .visit_markers (union_type .markers , p ))
273- union_type = union_type .padding .with_types ([ self .visit_right_padded (v , PyRightPadded .Location .UNION_TYPE_TYPES , p ) for v in union_type .padding .types ] )
273+ union_type = union_type .padding .with_types (list_map ( lambda v : self .visit_right_padded (v , PyRightPadded .Location .UNION_TYPE_TYPES , p ), union_type .padding .types ) )
274274 return union_type
275275
276276 def visit_variable_scope (self , variable_scope : VariableScope , p : P ) -> J :
@@ -280,7 +280,7 @@ def visit_variable_scope(self, variable_scope: VariableScope, p: P) -> J:
280280 return temp_statement
281281 variable_scope = cast (VariableScope , temp_statement )
282282 variable_scope = variable_scope .with_markers (self .visit_markers (variable_scope .markers , p ))
283- variable_scope = variable_scope .padding .with_names ([ self .visit_right_padded (v , PyRightPadded .Location .VARIABLE_SCOPE_NAMES , p ) for v in variable_scope .padding .names ] )
283+ variable_scope = variable_scope .padding .with_names (list_map ( lambda v : self .visit_right_padded (v , PyRightPadded .Location .VARIABLE_SCOPE_NAMES , p ), variable_scope .padding .names ) )
284284 return variable_scope
285285
286286 def visit_del (self , del_ : Del , p : P ) -> J :
@@ -290,7 +290,7 @@ def visit_del(self, del_: Del, p: P) -> J:
290290 return temp_statement
291291 del_ = cast (Del , temp_statement )
292292 del_ = del_ .with_markers (self .visit_markers (del_ .markers , p ))
293- del_ = del_ .padding .with_targets ([ self .visit_right_padded (v , PyRightPadded .Location .DEL_TARGETS , p ) for v in del_ .padding .targets ] )
293+ del_ = del_ .padding .with_targets (list_map ( lambda v : self .visit_right_padded (v , PyRightPadded .Location .DEL_TARGETS , p ), del_ .padding .targets ) )
294294 return del_
295295
296296 def visit_special_parameter (self , special_parameter : SpecialParameter , p : P ) -> J :
0 commit comments