code: def test_peephole_type_refinements(self):
      def refine(x):
          # type: (Optional[Tensor]) -> Tensor
          return x if x is not None else torch.tensor(3)
  
      @torch.jit.script
      def test():
          return refine(torch.tensor(4))
  
      FileCheck().check("prim::unchecked_cast").run(test.graph)
      self.run_pass("peephole", test.graph)
      FileCheck().check_not("prim::unchecked_cast").run(test.graph)
  
      # refinement not optimzied out
      def is_int_tensor(x):
          scalar = x.item()
          if isinstance(scalar, int):
              return scalar + 3
          else:
              return 8
  
      self.checkScript(is_int_tensor, (torch.tensor(2),))
      self.checkScript(is_int_tensor, (torch.tensor(2.5),))
      graph = torch.jit.script(is_int_tensor).graph
      self.run_pass("peephole", graph)
      FileCheck().check("prim::unchecked_cast").run(graph)
  
imports: import torch
  from torch.testing._internal.jit_utils import JitTestCase, RUN_CUDA, _inline_everything
  from torch import nn
  from torch.testing import FileCheck
  from typing import Callable, List
  import unittest
label_desc: Use image node_id 8 for calling the TestPeephole obj's underlying member method code with example usage: obj.test_peephole_type_refinements() and returns: unknown, refine, unknown, int