class_docstr: Tests for Importer and derived classes.
docstr: Exercise corner case where we try to pickle an object whose
  __module__ doesn't exist because it's from a C extension.
code: def test_package_importer_whichmodule_no_dunder_module(self):
      """Exercise corner case where we try to pickle an object whose
      __module__ doesn't exist because it's from a C extension.
      """
      # torch.float16 is an example of such an object: it is a C extension
      # type for which there is no __module__ defined. The default pickler
      # finds it using special logic to traverse sys.modules and look up
      # `float16` on each module (see pickle.py:whichmodule).
      #
      # We must ensure that we emulate the same behavior from PackageImporter.
      my_dtype = torch.float16
  
      # Set up a PackageImporter which has a torch.float16 object pickled:
      buffer = BytesIO()
      with PackageExporter(buffer) as exporter:
          exporter.save_pickle("foo", "foo.pkl", my_dtype)
      buffer.seek(0)
  
      importer = PackageImporter(buffer)
      my_loaded_dtype = importer.load_pickle("foo", "foo.pkl")
  
      # Re-save a package with only our PackageImporter as the importer
      buffer2 = BytesIO()
      with PackageExporter(buffer2, importer=importer) as exporter:
          exporter.save_pickle("foo", "foo.pkl", my_loaded_dtype)
  
      buffer2.seek(0)
  
      importer2 = PackageImporter(buffer2)
      my_loaded_dtype2 = importer2.load_pickle("foo", "foo.pkl")
      self.assertIs(my_dtype, my_loaded_dtype)
      self.assertIs(my_dtype, my_loaded_dtype2)
  
file_path: pytorch/test/package/test_importer.py
imports: from io import BytesIO
  import torch
  from torch.package import Importer, OrderedImporter, PackageExporter, PackageImporter, sys_importer
  from torch.testing._internal.common_utils import run_tests
label_desc: Use image node_id 6 for calling the TestImporter obj's underlying member method code with example usage: obj.test_package_importer_whichmodule_no_dunder_module() without return types