class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
code: def test_package_script_class_referencing_self(self):
      import package_a.fake_script_class as fake
  
      obj = fake.UsesIdListFeature()
      # intentionally script here to fill the compilation cache, to make sure
      # there is no false sharing between scripted types coming from the
      # package vs. outside environment.
      torch.jit.script(obj)
  
      buffer = BytesIO()
      with PackageExporter(buffer) as exporter:
          exporter.intern("**")
          exporter.save_pickle("obj", "obj.pkl", obj)
  
      buffer.seek(0)
      importer = PackageImporter(buffer)
      obj_loaded = importer.load_pickle("obj", "obj.pkl")
      scripted_obj_loaded = torch.jit.script(obj_loaded)
  
      # Make sure the scripted object can be serialized without error.
      buffer2 = scripted_obj_loaded.save_to_buffer()
      torch.jit.load(BytesIO(buffer2))
  
imports: from io import BytesIO
  from textwrap import dedent
  from unittest import skipIf
  import torch
  from torch.package import PackageExporter, PackageImporter
  from torch.testing._internal.common_utils import IS_FBCODE, IS_SANDCASTLE, run_tests
label_desc: Use image node_id 4 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_package_script_class_referencing_self() without return types