import textwrap
import re


def pytd_src(text):
  """Add a typing.Union import if needed."""
  text = textwrap.dedent(text)
  if "Union" in text and not re.search("typing.*Union", text):
    return "from typing import Union\n" + text
  else:
    return text