code: def _encode(data: Any, path: str, result: dict):
      if isinstance(data, dict) and "__kind__" in data:
          kind = data["__kind__"]
  
          if kind == Kind.Instance:
              result[join(path, "()")] = data["class"]
  
              for n, arg in enumerate(data.get("args", [])):
                  _encode(arg, join(path, n), result)
  
              for name, value in data["kwargs"].items():
                  _encode(value, join(path, name), result)
  
          elif kind == Kind.Stateful:
              result[join(path, "!")] = data["class"]
  
              for name, value in data["kwargs"].items():
                  _encode(value, join(path, name), result)
  
          elif kind == Kind.Type:
              result[join(path, "#")] = data["class"]
  
          else:
              raise ValueError(f"Unsupported kind `{kind}`.")
  
      else:
          result[path] = data
  
file_path: gluonts/src/gluonts/core/serde/flat.py
imports: from collections import defaultdict
  from itertools import count
  from typing import Any
  from toolz.dicttoolz import keymap, valmap
  from ._base import encode, Kind, decode
label_desc: Use image node_id 2 for calling a global function with example usage: _encode(data, path, result) without return types