_pickle.py 982 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # mypy: allow-untyped-defs
  2. # These functions are referenced from the pickle archives produced by
  3. # ScriptModule.save()
  4. # These (`build_*`) functions used to be used by `pickler.cpp` to specify
  5. # the type of the list for certain special types, but now all lists get
  6. # a type attached and restored via `restore_type_tag` below. The legacy
  7. # functions should stick around for backwards-compatibility.
  8. def build_intlist(data):
  9. return data
  10. def build_tensorlist(data):
  11. return data
  12. def build_doublelist(data):
  13. return data
  14. def build_boollist(data):
  15. return data
  16. def build_tensor_from_id(data):
  17. if isinstance(data, int):
  18. # just the id, can't really do anything
  19. return data
  20. def restore_type_tag(value, type_str):
  21. # The type_ptr is used by the jit unpickler to restore the full static type
  22. # to container types like list when they are re-loaded, but this doesn't
  23. # matter for Python, so just return the plain value
  24. return value