class_docstr: TaskGroup context is used to keep the current TaskGroup when TaskGroup is used as ContextManager.
class_docstr_tok: ["TaskGroup","context","is","used","to","keep","the","current","TaskGroup","when","TaskGroup","is","used","as","ContextManager","."]
docstr: Get the current TaskGroup.
docstr_tok: ["Get","the","current","TaskGroup","."]
code: def get_current_task_group(cls, dag: DAG | None) -> TaskGroup | None:
      """Get the current TaskGroup."""
      from airflow.models.dag import DagContext
  
      if not cls._context_managed_task_group:
          dag = dag or DagContext.get_current_dag()
          if dag:
              # If there's currently a DAG but no TaskGroup, return the root TaskGroup of the dag.
              return dag.task_group
  
      return cls._context_managed_task_group
  
imports: from __future__ import annotations
  import copy
  import functools
  import operator
  import weakref
  from typing import TYPE_CHECKING, Any, Generator, Iterator, Sequence
  import re2
  from airflow.compat.functools import cache
  from airflow.exceptions import AirflowDagCycleException, AirflowException, DuplicateTaskIdFound, TaskAlreadyInTaskGroup
  from airflow.models.taskmixin import DAGNode
  from airflow.serialization.enums import DagAttributeTypes
  from airflow.utils.helpers import validate_group_key
label_desc: Use image node_id 3 for calling the TaskGroupContext obj's underlying member method code with example usage: obj.get_current_task_group(cls, dag) and returns: cls, dag