Exemple #1
0
 def fix_map(self, original_node: Call, updated_node: Call) -> BaseExpression:
     # TODO test with CompFor etc.
     # TODO improve join test
     func_name = ensure_type(updated_node.func, Name).value
     if func_name not in self.builtins_imports:
         updated_node = Call(func=Name("list"), args=[Arg(updated_node)])
     return updated_node
 def leave_Return(
     self, original_node: Return, updated_node: Return
 ) -> Union[BaseSmallStatement, RemovalSentinel]:
     if self.visiting_permalink_method and m.matches(updated_node.value, m.Tuple()):
         elem_0 = updated_node.value.elements[0]
         elem_1_3 = updated_node.value.elements[1:3]
         args = (
             Arg(elem_0.value),
             Arg(Name("None")),
             *[Arg(el.value) for el in elem_1_3],
         )
         return updated_node.with_changes(
             value=Call(func=Name("reverse"), args=args)
         )
     return super().leave_Return(original_node, updated_node)
 def leave_Call(self, original_node: Call,
                updated_node: Call) -> BaseExpression:
     if m.matches(updated_node, m.Call(func=m.Name("url"))):
         return Call(args=updated_node.args, func=Name("re_path"))
     return super().leave_Call(original_node, updated_node)
Exemple #4
0
 def fix_not_iter(self, original_node: Call, updated_node: Call) -> BaseExpression:
     updated_node = Call(func=Name("list"), args=[Arg(updated_node)])
     return updated_node
Exemple #5
0
 def build_path_call(self, pattern, other_args):
     """Build the `Call` node using Django 2.0's `path()` function."""
     route = self.build_route(pattern)
     updated_args = (Arg(value=SimpleString(f"'{route}'")), *other_args)
     return Call(args=updated_args, func=Name("path"))
Exemple #6
0
 def update_call(self, updated_node: Call) -> BaseExpression:
     updated_args = self.update_call_args(updated_node)
     return Call(args=updated_args, func=Name(self.new_name))
Exemple #7
0
 def leave_Call(self, original_node: Call, updated_node: Call) -> BaseExpression:
     if m.matches(updated_node, m.Call(func=m.Name(self.old_name))):
         updated_args = self.update_call_args(updated_node)
         return Call(args=updated_args, func=Name(self.new_name))
     return super().leave_Call(original_node, updated_node)