code: def _get_nodes_affected_by_intervention(
      causal_graph: DirectedGraph, target_nodes: Iterable[Any]
  ) -> List[Any]:
      result = []
  
      for node in nx.topological_sort(causal_graph):
          if node in target_nodes:
              result.append(node)
              continue
  
          for target_node in target_nodes:
              if target_node in nx.ancestors(causal_graph, source=node):
                  result.append(node)
                  break
  
      return result
  
file_path: dowhy/dowhy/gcm/whatif.py
imports: from typing import Any, Callable, Dict, Iterable, List, Optional, Union
  import networkx
  import numpy
  import pandas
  from dowhy.gcm._noise import compute_noise_from_data
  from dowhy.gcm.causal_mechanisms import ClassifierFCM
  from dowhy.gcm.causal_models import InvertibleStructuralCausalModel, ProbabilisticCausalModel, StructuralCausalModel, validate_causal_dag
  from dowhy.gcm.fitting_sampling import draw_samples
  from dowhy.graph import DirectedGraph, get_ordered_predecessors, is_root_node, node_connected_subgraph_view, validate_node_in_graph
label_desc: Use image node_id 3 for calling a global function with example usage: _get_nodes_affected_by_intervention(causal_graph, target_nodes) and returns: result