Skip to content

可否提供 load 方法,用于载入 dump 方法导出的数据,以便于用户缓存数据 #492

Description

@Ma233

无法直接通过 __init__ 方法还原一个 dump 出来的数据,所以自己做了一个:

class Object:
    @classmethod
    def load(cls, attrs):
        obj, meta_date = cls(), dict()

        for k in ("createdAt", "updatedAt"):
            v = attrs.pop(k, None)
            if v is not None:
                meta_date[k] = v
                obj._attributes[k] = utils.decode(k, v)

        obj._merge_metadata(meta_date)

        # 此处不能直接 obj.set(attrs),否则 Pointer 类型会被当做字典设置到字段上
        for k, v in attrs.items():
            obj.set(k, v)

        return obj

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions