Source code for pyadi.nodes
from astunparse.astnode import ASTNode, Constant, Name
[docs]
class keyword(ASTNode):
[docs]
def __init__(self, arg, value):
self._class = 'keyword'
self.arg = arg
self.value = value
[docs]
class arguments(ASTNode):
[docs]
def __init__(self, args):
self._class = 'arguments'
self.args = args
self.defaults = []
self.vararg = None
self.kwarg = None
[docs]
class arg(ASTNode):
[docs]
def __init__(self, arg):
self._class = 'arg'
self.arg = arg
self.annotation = None
[docs]
class FunctionDef(ASTNode):
[docs]
def __init__(self, name, args, l):
self._class = 'FunctionDef'
self.name = name
self.args = arguments([arg(n) for n in args])
self.body = l
self.decorator_list = []
[docs]
class Lambda(ASTNode):
[docs]
def __init__(self, args, l):
self._class = 'Lambda'
self.args = arguments([arg(n) for n in args])
self.body = l
[docs]
class Return(ASTNode):
[docs]
def __init__(self, val):
self._class = 'Return'
self.value = val
[docs]
class Assign(ASTNode):
[docs]
def __init__(self, l, r):
self._class = 'Assign'
if not isinstance(l, list):
l = [l]
self.targets = l
self.value = r
[docs]
class List(ASTNode):
[docs]
def __init__(self, elts):
self._class = 'List'
self.elts = elts
[docs]
class Tuple(ASTNode):
[docs]
def __init__(self, elts):
self._class = 'Tuple'
self.elts = elts
[docs]
class Module(ASTNode):
[docs]
def __init__(self, body):
self._class = 'Module'
self.body = body
[docs]
class Slice(ASTNode):
[docs]
def __init__(self, l, u=None, s=None):
self._class = 'Slice'
self.lower = Constant(l) if isinstance(l, int) else l
self.upper = Constant(u) if isinstance(u, int) else u
self.step = Constant(s) if isinstance(s, int) else s
[docs]
class Subscript(ASTNode):
[docs]
def __init__(self, v, ind):
self._class = "Subscript"
self.value = v
if isinstance(ind, int):
self.slice = Constant(ind)
else:
self.slice = ind
[docs]
class Attribute(ASTNode):
[docs]
def __init__(self, v, attr):
self._class = "Attribute"
self.value = v
self.attr = attr
[docs]
class Call(ASTNode):
[docs]
def __init__(self, func, args=[], kw=[]):
self._class = "Call"
if isinstance(func, str):
self.func = Name(func)
else:
self.func = func
if not isinstance(args, list):
args = [args]
self.args = args
self.keywords = kw
[docs]
class Keyword(ASTNode):
[docs]
def __init__(self, arg, value):
self._class = "Keyword"
self.arg = arg
self.value = value
[docs]
class Starred(ASTNode):
[docs]
def __init__(self, value):
self._class = "Starred"
self.value = value
[docs]
class UnaryOp(ASTNode):
[docs]
def __init__(self, op, value=None):
self._class = "UnaryOp"
self.op = op
self.operand = value
[docs]
class BinOp(ASTNode):
[docs]
def __init__(self, op, left=None, right=None):
self._class = "BinOp"
self.op = op
self.left = left
self.right = right
[docs]
class AugAssign(ASTNode):
[docs]
def __init__(self, op, target=None, value=None):
self._class = "AugAssign"
self.op = op
self.target = target
self.value = value
# (c) 2023 AI & IT UG
# Author: Johannes Willkomm jwillkomm@ai-and-it.de