docstr: Test that using an optional with no contained types produces an error.
docstr_tok: ["Test","that","using","an","optional","with","no","contained","types","produces","an","error","."]
code: def test_optional_no_element_type_annotation(self):
      """
      Test that using an optional with no contained types produces an error.
      """
  
      def fn_with_comment(x: torch.Tensor) -> Optional:
          return (x, x)
  
      def annotated_fn(x: torch.Tensor) -> Optional:
          return (x, x)
  
      with self.assertRaisesRegex(
          RuntimeError,
          r"Attempted to use Optional without a contained type",
      ):
          cu = torch.jit.CompilationUnit()
          cu.define(dedent(inspect.getsource(fn_with_comment)))
  
      with self.assertRaisesRegex(
          RuntimeError,
          r"Attempted to use Optional without a contained type",
      ):
          cu = torch.jit.CompilationUnit()
          cu.define(dedent(inspect.getsource(annotated_fn)))
  
      with self.assertRaisesRegex(
          RuntimeError,
          r"Attempted to use Optional without a contained type",
      ):
          torch.jit.script(fn_with_comment)
  
      with self.assertRaisesRegex(
          RuntimeError,
          r"Attempted to use Optional without a contained type",
      ):
          torch.jit.script(annotated_fn)
  
imports: from collections import namedtuple
  from typing import Dict, Iterator, List, Optional, Tuple
  from torch.testing._internal.jit_utils import JitTestCase
  from torch.testing import FileCheck
  from textwrap import dedent
  from jit.test_module_interface import TestModuleInterface
  import inspect
  import os
  import sys
  import torch
  import torch.testing._internal.jit_utils
label_desc: Use image node_id 7 for calling the TestTypesAndAnnotation obj's underlying member method code with example usage: obj.test_optional_no_element_type_annotation() and returns: x,  x, x,  x