test_roundtrips.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:cattrs 作者: Tinche 项目源码 文件源码
def test_optional_field_roundtrip(converter, cl_and_vals):
    """
    Classes with optional fields can be unstructured and structured.
    """
    cl, vals = cl_and_vals

    @attr.s
    class C(object):
        a = attr.ib(type=Optional[cl])

    inst = C(a=cl(*vals))
    assert inst == converter.structure(converter.unstructure(inst), C)

    inst = C(a=None)
    unstructured = converter.unstructure(inst)

    assert inst == converter.structure(unstructured, C)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号