def translate_pat_Num(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) comparator = astx.copy_node(pat) condition = ast.Compare(left=scrutinee_trans_copy, ops=[ast.Eq()], comparators=[comparator]) return (condition, _util.odict())
def translate_pat_Num(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) comparator = astx.copy_node(pat) condition = ast.Compare( left=scrutinee_trans_copy, ops=[ast.Eq()], comparators=[comparator]) return (condition, _util.odict())
def translate_pat_Num(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) comparator = astx.copy_node(pat) n = pat.n if not isinstance(n, complex): comparator.n = complex(n) condition = ast.Compare(left=scrutinee_trans_copy, ops=[ast.Eq()], comparators=[comparator]) return (condition, _util.odict())
def translate_pat_Num(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) comparator = astx.copy_node(pat) n = pat.n if not isinstance(n, complex): comparator.n = complex(n) condition = ast.Compare( left=scrutinee_trans_copy, ops=[ast.Eq()], comparators=[comparator]) return (condition, _util.odict())
def translate_pat_Call_constructor(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) args, keywords = pat.args, pat.keywords idx = self.idx conditions = [] binding_translations = _util.odict() for i, arg in enumerate(args): n = _util.odict_idx_of(idx, i) elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( arg, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) for keyword in keywords: n = _util.odict_idx_of(idx, keyword.arg) elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( keyword.value, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) condition = ast.BoolOp( op=ast.And(), values=conditions) return (condition, binding_translations)
def translate_Compare(self, ctx, e): translation = astx.copy_node(e) translation.left = ctx.translate(e.left) translation.comparators = ( ctx.translate(comparator) for comparator in e.comparators) return translation
def translate_pat_Call_constructor(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) args, keywords = pat.args, pat.keywords idx = self.idx conditions = [] binding_translations = _util.odict() for i, arg in enumerate(args): n = _util.odict_idx_of(idx, i) elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( arg, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) for keyword in keywords: n = _util.odict_idx_of(idx, keyword.arg) elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( keyword.value, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) condition = ast.BoolOp(op=ast.And(), values=conditions) return (condition, binding_translations)
def translate_Compare(self, ctx, e): translation = astx.copy_node(e) translation.left = ctx.translate(e.left) translation.comparators = tuple( ctx.translate(comparator) for comparator in e.comparators) return translation
def translate_Call(self, ctx, e): func, args = e.func, e.args translation = astx.copy_node(e) translation.func = ctx.translate(func) translation.args = list( ctx.translate(arg) for arg in args) return translation
def translate_Subscript(self, ctx, e): translation = astx.copy_node(e) translation.value = ctx.translate(e.value) slice_ = e.slice slice_translation = astx.copy_node(slice_) if isinstance(slice_, ast.Index): slice_translation.value = ctx.translate(slice_.value) else: lower, upper, step = slice_.lower, slice_.upper, slice_.step slice_translation.lower = ctx.translate(lower) if lower is not None else None slice_translation.upper = ctx.translate(upper) if upper is not None else None if not _is_None(step): slice_translation.step = ctx.translate(step) else: slice_translation.step = None translation.slice = slice_translation return translation
def translate_pat_Tuple(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) elts = pat.elts idx = self.idx conditions = [] binding_translations = _util.odict() for n, (elt, ty) in enumerate(zip(elts, idx.itervalues())): elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( elt, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) condition = ast.BoolOp(op=ast.And(), values=conditions) return (condition, binding_translations)
def translate_pat_Dict(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) keys, values = pat.keys, pat.values idx = self.idx conditions = [] binding_translations = _util.odict() for key, value in zip(keys, values): label = key.label n = _util.odict_idx_of(idx, label) elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( value, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) condition = ast.BoolOp(op=ast.And(), values=conditions) return (condition, binding_translations)
def translate_pat_Tuple(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) elts = pat.elts idx = self.idx conditions = [] binding_translations = _util.odict() for n, (elt, ty) in enumerate(zip(elts, idx.itervalues())): elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( elt, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) condition = ast.BoolOp( op=ast.And(), values=conditions) return (condition, binding_translations)
def translate_pat_Dict(self, ctx, pat, scrutinee_trans): scrutinee_trans_copy = astx.copy_node(scrutinee_trans) keys, values = pat.keys, pat.values idx = self.idx conditions = [] binding_translations = _util.odict() for key, value in zip(keys, values): label = key.label n = _util.odict_idx_of(idx, label) elt_scrutinee_trans = astx.make_Subscript_Num_Index( scrutinee_trans_copy, n) elt_condition, elt_binding_translations = ctx.translate_pat( value, elt_scrutinee_trans) conditions.append(elt_condition) binding_translations.update(elt_binding_translations) condition = ast.BoolOp( op=ast.And(), values=conditions) return (condition, binding_translations)
def translate_Tuple(self, ctx, e): translation = astx.copy_node(e) translation.elts = tuple( ctx.translate(elt) for elt in e.elts) return translation
def translate_Num(self, ctx, e): return astx.copy_node(e)
def translate_Num(self, ctx, e): translation = astx.copy_node(e) n = e.n if not isinstance(n, complex): translation.n = complex(n) return translation
def translate_Num(self, ctx, e): translation = astx.copy_node(e) translation.n = float(e.n) return translation
def translate_BinOp(self, ctx, e): translation = astx.copy_node(e) translation.left = ctx.translate(e.left) translation.right = ctx.translate(e.right) return translation
def translate_UnaryOp(self, ctx, e): translation = astx.copy_node(e) translation.operand = ctx.translate(e.operand) return translation
def translate_Attribute(self, ctx, e): translation = astx.copy_node(e) translation.value = ctx.translate(e.value) return translation
def translate_Num(self, ctx, e): return astx.copy_node(e)
def translate_Name(cls, ctx, e): translation = astx.copy_node(e) translation.id = e.uniq_id return translation
def translate_BoolOp(self, ctx, e): translation = astx.copy_node(e) translation.values = tuple( ctx.translate(value) for value in e.values) return translation
def translate_UnaryOp(self, ctx, e): translation = astx.copy_node(e) translation.operand = ctx.translate(e.operand) return translation
def translate_Attribute(self, ctx, e): translation = astx.copy_node(e) translation.value = ctx.translate(e.value) return translation
def translate_Tuple(self, ctx, e): translation = astx.copy_node(e) translation.elts = tuple(ctx.translate(elt) for elt in e.elts) return translation
def translate_Num(self, ctx, e): translation = astx.copy_node(e) translation.n = float(e.n) return translation
def translate_Num(self, ctx, e): translation = astx.copy_node(e) n = e.n if not isinstance(n, complex): translation.n = complex(n) return translation
def translate_BinOp(self, ctx, e): translation = astx.copy_node(e) translation.left = ctx.translate(e.left) translation.right = ctx.translate(e.right) return translation
def translate_Name_constructor(self, ctx, e): return astx.copy_node(e)