code: def craft(spec):
      """Instantiate an object from the specification string.
  
      Parameters
      ----------
      spec : str, sktime/skbase compatible object specification
          i.e., a string that executes to construct an object if all imports were present
          imports inferred are of any classes in the scope of ``all_estimators``
          option 1: a string that evaluates to an estimator
          option 2: a sequence of assignments in valid python code,
              with the object to be defined preceded by a "return"
              assignments can use names of classes as if all imports were present
  
      Returns
      -------
      obj : skbase BaseObject descendant, constructed from ``spec``
          this will have the property that ``spec == str(obj)`` (up to formatting)
      """
      register = dict(all_estimators())  # noqa: F841
  
      for x in _extract_class_names(spec):
          exec(f"{x} = register['{x}']")
  
      try:
          obj = eval(spec)
      except Exception:
          from textwrap import indent
  
          spec_fun = indent(spec, "    ")
          spec_fun = (
              """
  def build_obj():
          """
              + spec_fun
          )
          exec(spec_fun, locals())
          obj = eval("build_obj()")
  
      return obj
  
imports: import re
  from sktime.registry._lookup import all_estimators
label_desc: Use image node_id 2 for calling a global function with example usage: craft(spec) and returns: obj