Beispiel #1
0
 def transform(self, node: ast.Assign) -> ast.Assign:
     new_assign = ast.Assign(parent=node.parent)
     value = ast.Call(parent=new_assign)
     iterator = node.value.generators[0].iter
     iterator.parent = value
     value.postinit(
         func=ast.Name(name="map", parent=value),
         args=[ast.Name(node.value.elt.func.name, parent=value), iterator])
     targets = node.targets
     for target in targets:
         target.parent = new_assign
     new_assign.postinit(targets=node.targets, value=value)
     return new_assign
Beispiel #2
0
 def transform(self, node: ast.Name) -> ast.Name:
     return ast.Name(
         lineno=node.lineno,
         col_offset=node.col_offset,
         parent=node.parent,
         name=self.new_name,
     )
Beispiel #3
0
 def transform(self, node: ast.Call) -> ast.Call:
     new_call = ast.Call(parent=node.parent)
     new_name = ast.Name(self.new_name, parent=new_call.parent)
     new_call.postinit(func=new_name,
                       args=node.args,
                       keywords=node.keywords)
     return new_call
Beispiel #4
0
 def transform(self, node: ast.Module) -> ast.Module:
     new_node = node
     new_assign = ast.Assign()
     new_assign.postinit(
         targets=[ast.AssignName(name=self.new_name, parent=new_assign)],
         value=ast.Name(name=self.old_name, parent=new_assign),
     )
     new_node.body = [new_assign] + node.body
     return new_node
def create_format_spec_node(node: ast.Call, value: ast.Name, format_spec: str) -> ast.FormattedValue:
    formatted_value_node = ast.FormattedValue(lineno=node.lineno, col_offset=node.col_offset, parent=node.parent)
    specifications: Optional[ast.JoinedStr]
    if format_spec:
        specifications = ast.JoinedStr(lineno=node.lineno, col_offset=node.col_offset, parent=node.parent,)
        specifications.postinit(values=[ast.Const(format_spec.replace(":", ""))])
    else:
        specifications = None

    formatted_value_node.postinit(value=ast.Name(value.name), format_spec=specifications)

    return formatted_value_node
def name_node(draw, name=None):
    if not name:
        node = astroid.Name(draw(valid_identifier()))
    else:
        node = astroid.Name(draw(name))
    return node