code: def _init_currency(
      currency: Union[currencies.CurrencyProtoType, str]
  ) -> currencies.CurrencyProtoType:
      """Converts input to a currency object."""
      if isinstance(currency, str):
          try:
              return getattr(currencies.Currency, currency)
          except KeyError:
              raise ValueError(f"{currency} is not a valid currency")
      return currency
  
file_path: tf-quant-finance/tf_quant_finance/experimental/pricing_platform/framework/core/curve_types.py
imports: from typing import Union
  import dataclasses
  from tf_quant_finance.experimental.pricing_platform.framework.core import currencies
  from tf_quant_finance.experimental.pricing_platform.framework.core import rate_indices
label_desc: Use image node_id 1 for calling a global function with example usage: _init_currency(currency) and returns: currency, getattr