code: def _maybe_open(
      path_or_file: Union[str, pathlib.Path, BinaryIO], mode: str
  ):
      """A function that unifies handling of file objects and path-like objects
      by opening the latter."""
      if isinstance(path_or_file, (str, pathlib.Path)):
          file = open(_with_suffix(path_or_file), mode)
          try:
              yield file
          finally:
              file.close()
      else:  # file-like object
          yield path_or_file
  
imports: import functools
  import pathlib
  from collections.abc import Callable
  from contextlib import contextmanager
  from typing import Any, BinaryIO, Optional, Union
  import jax
  import jax.numpy
  import jax.tree_util
  import numpy
  from jaxtyping import PyTree
  from ._filters import is_array_like
label_desc: Use image node_id 5 for calling a global function with example usage: _maybe_open(path_or_file, mode) without return types