code: def test_moduledict_keyerror(self):
      class BadModule(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.moduledict = torch.nn.ModuleDict(
                  {"foo": None, "bar": None}
              )
  
          def forward(self, input):
              assert (
                  self.moduledict["blah"] == "blah"
              ), "this is a keyerror"
  
      with self.assertRaisesRegexWithHighlight(
          RuntimeError, "Key Error, blah", "self.moduledict['blah'"
      ):
          b = BadModule()
          torch.jit.script(b)
  
      class AnotherBadModule(torch.nn.Module):
          def __init__(self):
              super().__init__()
              self.moduledict = torch.nn.ModuleDict(
                  {"foo": None, "bar": None}
              )
  
          def forward(self, input):
              idx = "blah"
              assert (
                  self.moduledict[idx] == "blah"
              ), "this is a string literal error"
  
      with self.assertRaisesRegexWithHighlight(
          RuntimeError,
          "Unable to extract string literal index. "
          "ModuleDict indexing is only supported with string literals. "
          "For example, 'i = \"a\"; self.layers\\[i\\]\\(x\\)' will fail "
          "because i is not a literal.",
          "self.moduledict[idx]",
      ):
          b = AnotherBadModule()
          torch.jit.script(b)
  
imports: import os
  import sys
  from typing import Any, List, Tuple
  from collections import OrderedDict
  import torch
  import torch.nn
  from torch.testing._internal.jit_utils import JitTestCase
label_desc: Use image node_id 9 for calling the TestModuleContainers obj's underlying member method code with example usage: obj.test_moduledict_keyerror() without return types