code: def has_metadata(trait, metadata, value=None, recursive=True):
      """
      Checks if a given trait has a metadata (and optionally if it is set to particular value)
      """
      count = 0
      if (
          hasattr(trait, "_metadata")
          and metadata in list(trait._metadata.keys())
          and (trait._metadata[metadata] == value or value is None)
      ):
          count += 1
      if recursive:
          if hasattr(trait, "inner_traits"):
              for inner_trait in trait.inner_traits():
                  count += has_metadata(
                      inner_trait.trait_type, metadata, recursive
                  )
          if hasattr(trait, "handlers") and trait.handlers is not None:
              for handler in trait.handlers:
                  count += has_metadata(handler, metadata, recursive)
  
      return count > 0
  
imports: from collections.abc import Sequence
  from traits import __version__
  import traits.api
  from traits.api import TraitType, Unicode
  from traits.trait_base import _Undefined
  from pathlib import Path
  from ...utils.filemanip import path_resolve
label_desc: Use image node_id 3 for calling a global function with example usage: has_metadata(trait, metadata, value, recursive) and returns: unknown