? ( __reduce__
)? ?
: __reduce__
( !), . , __reduce__
__reduce__
( , )!
dict
, . , __setitem__
, . __setitem__
_dict_type
. , None
,
TypeError: isinstance() arg 2 must be a type or tuple of types
, TypedDict
__reduce__
, -. __setitem__
, :
my_dict = TypedDict(int)
with open('out.pkl', 'wb') as fin:
pickle.dump(my_dict, fin)
with open('out.pkl', 'rb') as fin:
out = pickle.load(fin)
print(out._dict_type)
, , __reduce__
, dicts, __reduce__
- ( , __reduce__
):
>>> d = {1: 1}
>>> dict.__reduce__(d)
TypeError: "can't pickle dict objects"
>>> d = TypedDict(int)
>>> dict.__reduce__(d)
(<function copyreg._reconstructor>,
(__main__.TypedDict, dict, {}),
{'_dict_type': int})