def __new__(cls, car, cdr): if isinstance(cdr, list): # Keep unquotes in the cdr of conses if type(cdr) == HyExpression: if len(cdr) > 0 and type(cdr[0]) == HySymbol: if cdr[0] in ("unquote", "unquote_splice"): return super(HyCons, cls).__new__(cls) return cdr.__class__([_wrap_value(car)] + cdr) elif cdr is None: return HyExpression([_wrap_value(car)]) else: return super(HyCons, cls).__new__(cls)
def __init__(self, car, cdr): self.car = _wrap_value(car) self.cdr = _wrap_value(cdr)
def test_wrap_long_type(): """ Test conversion of integers.""" wrapped = _wrap_value(long_type(0)) assert type(wrapped) == HyInteger
def test_wrap_nested_expr(): """ Test conversion of HyExpressions with embedded non-HyObjects.""" wrapped = _wrap_value(HyExpression([long_type(0)])) assert type(wrapped) == HyExpression assert type(wrapped[0]) == HyInteger assert wrapped == HyExpression([HyInteger(0)])
def test_wrap_tuple(): """ Test conversion of tuples.""" wrapped = _wrap_value((HyInteger(0),)) assert type(wrapped) == HyList assert type(wrapped[0]) == HyInteger assert wrapped == HyList([HyInteger(0)])