class_docstr: Tests for compatibility with TorchScript.
class_docstr_tok: ["Tests","for","compatibility","with","TorchScript","."]
docstr: Test a case where the interface defined in the package is
  different than the one defined in the loading environment, to make
  sure TorchScript can distinguish between the two.
docstr_tok: ["Test","a","case","where","the","interface","defined","in","the","package","is","different","than","the","one","defined","in","the","loading","environment",",","to","make","sure","TorchScript","can","distinguish","between","the","two","."]
code: def test_different_package_interface(self):
      """Test a case where the interface defined in the package is
      different than the one defined in the loading environment, to make
      sure TorchScript can distinguish between the two.
      """
      # Import one version of the interface
      import package_a.fake_interface as fake
  
      # Simulate a package that contains a different version of the
      # interface, with the exact same name.
      buffer = BytesIO()
      with PackageExporter(buffer) as pe:
          pe.save_source_string(
              fake.__name__,
              dedent(
                  """\
                      import torch
                      from torch import Tensor
  
                      @torch.jit.interface
                      class ModuleInterface(torch.nn.Module):
                          def one(self, inp1: Tensor) -> Tensor:
                              pass
  
                      class ImplementsInterface(torch.nn.Module):
                          def one(self, inp1: Tensor) -> Tensor:
                              return inp1 + 1
  
                      class UsesInterface(torch.nn.Module):
                          proxy_mod: ModuleInterface
  
                          def __init__(self):
                              super().__init__()
                              self.proxy_mod = ImplementsInterface()
  
                          def forward(self, input: Tensor) -> Tensor:
                              return self.proxy_mod.one(input)
                      """
              ),
          )
      buffer.seek(0)
  
      package_importer = PackageImporter(buffer)
      diff_fake = package_importer.import_module(fake.__name__)
      # We should be able to script successfully.
      torch.jit.script(diff_fake.UsesInterface())
  
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 2 for calling the TestPackageScript obj's underlying member method code with example usage: obj.test_different_package_interface() without return types