cloudpipe/cloudpickle

Classes with `cached_property` can't be cloudpickled

Open

#438 创建于 2021年8月31日

在 GitHub 查看
 (3 评论) (1 反应) (0 负责人)Python (1,407 star) (152 fork)batch import
enhancementhelp wanted

描述

I believe this is a bug.

Here is an example:

from functools import cached_property
import pickle
import cloudpickle


class MyExample:
    def __init__(self, foo):
        self.foo = foo

    @cached_property
    def bar(self) -> int:
        return self.foo * 3


example = MyExample(2)
pickle.dumps(example)      # works
cloudpickle.dumps(example) # crashes

This fails with TypeError: cannot pickle '_thread.RLock' object.

贡献者指南