code: def needs_expansion(task: AbstractOperator) -> TypeGuard[Operator]:
      """Whether a task needs expansion at runtime.
  
      A task needs expansion if it either
  
      * Is a mapped operator, or
      * Is in a mapped task group.
  
      This is implemented as a free function (instead of a property) so we can
      make it a type guard.
      """
      if isinstance(task, MappedOperator):
          return True
      if task.get_closest_mapped_task_group() is not None:
          return True
      return False
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, Union
  from airflow.models.baseoperator import BaseOperator
  from airflow.models.mappedoperator import MappedOperator
label_desc: Use image node_id 1 for calling a global function with example usage: needs_expansion(task) and returns: False, True, True