class_docstr: A suite of tests for profile directed typing in TorchScript.
class_docstr_tok: ["A","suite","of","tests","for","profile","directed","typing","in","TorchScript","."]
code: def test_nonetype_as_optional_of_type(self):
      def test_none(a) -> Any:
          if a is None:
              return 0
          else:
              return a + torch.ones(1)
  
      make_global(test_none)
  
      scripted_fn = torch.jit.script(
          test_none, example_inputs=[(None,), (10.6,)]
      )
      self.assertEqual(
          scripted_fn(
              30.9,
          ),
          test_none(
              30.9,
          ),
      )
  
      scripted_fn = torch.jit.script(
          test_none, example_inputs=[(None,), (10,)]
      )
      self.assertEqual(
          scripted_fn(
              2,
          ),
          test_none(
              2,
          ),
      )
  
      scripted_fn = torch.jit.script(
          test_none, example_inputs=[(None,), (torch.Tensor(1),)]
      )
      self.assertEqual(
          scripted_fn(
              torch.ones(1),
          ),
          test_none(
              torch.ones(1),
          ),
      )
  
imports: import os
  import sys
  import torch
  from torch.testing._internal.jit_utils import JitTestCase, make_global
  from torch.jit._monkeytype_config import _IS_MONKEYTYPE_INSTALLED
  from typing import List, Dict, Tuple, Any, Optional, NamedTuple
  from torch.testing._internal.common_utils import NoTest
label_desc: Use image node_id 18 for calling the TestPDT obj's underlying member method code with example usage: obj.test_nonetype_as_optional_of_type() and returns: int, unknown