def transform(self, node, results): future_import(u"division", node) touch_import_top(u'past.utils', u'old_div', node) expr1, expr2 = results[0].clone(), results[1].clone() # Strip any leading space for the first number: expr1.prefix = u'' return wrap_in_fn_call("old_div", expr1, expr2, prefix=node.prefix)
def match(self, node): u""" Since the tree needs to be fixed once and only once if and only if it matches, we can start discarding matches after the first. """ if node.type == self.syms.term: matched = False skip = False children = [] for child in node.children: if skip: skip = False continue if match_division(child) and not is_floaty(child): matched = True # Strip any leading space for the first number: children[0].prefix = u'' children = [wrap_in_fn_call("old_div", children + [Comma(), child.next_sibling.clone()], prefix=node.prefix)] skip = True else: children.append(child.clone()) if matched: return Node(node.type, children, fixers_applied=node.fixers_applied) return False
def match(self, node): u""" Since the tree needs to be fixed once and only once if and only if it matches, we can start discarding matches after the first. """ if node.type == self.syms.term: matched = False skip = False children = [] for child in node.children: if skip: skip = False continue if match_division(child) and not is_floaty(child): matched = True # Strip any leading space for the first number: children[0].prefix = u'' children = [ wrap_in_fn_call( "old_div", children + [Comma(), child.next_sibling.clone()], prefix=node.prefix) ] skip = True else: children.append(child.clone()) if matched: return Node(node.type, children, fixers_applied=node.fixers_applied) return False
def transform(self, node, results): if node.type == token.STRING: touch_import_top(u'past.types', u'oldstr', node) if _literal_re.match(node.value): new = node.clone() # Strip any leading space or comments: # TODO: check: do we really want to do this? new.prefix = u'' new.value = u'b' + new.value wrapped = wrap_in_fn_call("oldstr", [new], prefix=node.prefix) return wrapped
def transform(self, node, results): if self.skip: return future_import(u"division", node) expr1, expr2 = results[0].clone(), results[1].clone() # Strip any leading space for the first number: expr1.prefix = u'' # if expr1 or expr2 are obviously floats, we don't need to wrap in # old_div, as the behavior of division between any number and a float # should be the same in 2 or 3 if _is_floaty(expr1) or _is_floaty(expr2): return touch_import_top(u'past.utils', u'old_div', node) return wrap_in_fn_call("old_div", (expr1, expr2), prefix=node.prefix)
def match(self, node): u""" Since the tree needs to be fixed once and only once if and only if it matches, we can start discarding matches after the first. """ if node.type == self.syms.term: matched = False skip = False children = [] for child in node.children: if skip: skip = False continue if match_division(child) and not is_floaty(child): matched = True # Strip any leading space for the first number: children[0].prefix = u'' children = [ wrap_in_fn_call( "old_div", children + [Comma(), child.next_sibling.clone()], prefix=node.prefix) ] skip = True else: children.append(child.clone()) if matched: # In Python 2.6, `Node` does not have the fixers_applied attribute # https://github.com/python/cpython/blob/8493c0cd66cfc181ac1517268a74f077e9998701/Lib/lib2to3/pytree.py#L235 if hasattr(Node, "fixers_applied"): return Node(node.type, children, fixers_applied=node.fixers_applied) else: return Node(node.type, children) return False
def transform(self, node, results): if self.skip: return future_import(u"division", node) touch_import_top(u'past.utils', u'old_div', node) return wrap_in_fn_call("old_div", results, prefix=node.prefix)
def transform(self, node, results): expr1, expr2 = results[0].clone(), results[1].clone() # Strip any leading space for the first number: expr1.prefix = u'' return wrap_in_fn_call("old_div", expr1, expr2, prefix=node.prefix)
def transform(self, node, results): if self.skip: return future_import(u"division", node) touch_import_top(u"past.utils", u"old_div", node) return wrap_in_fn_call("old_div", results, prefix=node.prefix)