code: def set_named_term_type(
      self,
      name: str,
      new_term: GrammarTerm,
      term_type: Optional[str] = None,
  ) -> None:
      new_grammar = []
      for term in self.grammar:
          found = False
          if term.name == name:
              if term_type is not None and term.type == term_type:
                  found = True
              elif term_type is None:
                  found = True
          if not found:
              new_grammar.append(term)
          else:
              new_grammar.append(new_term)
      self.grammar = new_grammar
  
imports: from __future__ import annotations
  import socket
  from typing import Any
  from typing import Callable
  from typing import Dict
  from typing import List
  from typing import Optional
  from typing import Tuple
  from typing import Union
  from .deps import allowed_hosts
  from .lib import find_available_port
label_desc: Use image node_id 5 for calling the GrammarVerb obj's underlying member method code with example usage: obj.set_named_term_type(name, new_term, term_type) without return types