code: def test_flatten_dict():
      """Validate flatten_dict can handle nested dictionaries and argparse Namespace."""
      # Test basic dict flattening with custom delimiter
      params = {"a": {"b": "c"}}
      params = _flatten_dict(params, "--")
  
      assert "a" not in params
      assert params["a--b"] == "c"
  
      # Test complex nested dict flattening
      params = {
          "a": {5: {"foo": "bar"}},
          "b": 6,
          "c": {7: [1, 2, 3, 4], 8: "foo", 9: {10: "bar"}},
      }
      params = _flatten_dict(params)
  
      assert "a" not in params
      assert params["a/5/foo"] == "bar"
      assert params["b"] == 6
      assert params["c/7"] == [1, 2, 3, 4]
      assert params["c/8"] == "foo"
      assert params["c/9/10"] == "bar"
  
      # Test flattening of argparse Namespace
      params = Namespace(a=1, b=2)
      wrapping_dict = {"params": params}
      params = _flatten_dict(wrapping_dict)
  
      params_type = type(
          params
      )  # way around needed for Ruff's `isinstance` suggestion
      assert params_type is dict
      assert params["params/a"] == 1
      assert params["params/b"] == 2
      assert "a" not in params
      assert "b" not in params
  
      # Test flattening of dataclass objects
      @dataclass
      class A:
          c: int
          d: int
  
      @dataclass
      class B:
          a: A
          b: int
  
      params = {"params": B(a=A(c=1, d=2), b=3), "param": 4}
      params = _flatten_dict(params)
      assert params == {
          "param": 4,
          "params/b": 3,
          "params/a/c": 1,
          "params/a/d": 2,
      }
  
file_path: pytorch-lightning/tests/tests_fabric/utilities/test_logger.py
imports: from argparse import Namespace
  from dataclasses import dataclass
  import numpy
  import torch
  from lightning.fabric.utilities.logger import _add_prefix, _convert_params, _flatten_dict, _sanitize_callable_params, _sanitize_params
label_desc: Use image node_id 2 for calling a global function with example usage: test_flatten_dict() without return types