code: def to_bytes(
      s: types.AnyStr,
      *,
      encoding: str = "utf-8",
      errors: str = "strict",
  ) -> bytes:
      """Coerce string ``s`` to bytes."""
      if isinstance(s, str):
          return s.encode(encoding, errors)
      elif isinstance(s, bytes):
          return s
      else:
          raise TypeError(
              errors_.type_invalid_msg("s", type(s), Union[str, bytes])
          )
  
imports: from __future__ import annotations
  import inspect
  import logging
  import pathlib
  import sys
  import warnings
  from typing import Any, Callable, Collection, Iterable, Literal, Optional, Type, Union, cast
  from .None import errors
  from .None import types
label_desc: Use image node_id 9 for calling a global function with example usage: to_bytes(s) and returns: s, s