def replace(node, **kw):
    """Equivalent to namedtuple's _replace.
    When **kw is empty simply returns node itself.
    
    >>> o = BinOp(Add(), NumberConstant(2), NumberConstant(3))
    >>> o2 = replace(o, op=Sub(), left=NumberConstant(3))
    >>> print(o, o2)
    (2 + 3) (3 - 3)
    """
    if kw:
        vals = dict(node)
        vals.update(**kw)
        return node.__class__(**vals)
    else:
        return node
