code: def write_file(filename: str, new_contents: str) -> None:
      """Write new content to file, iff the content changed."""
      try:
          with open(filename, encoding="utf-8") as fp:
              old_contents = fp.read()
  
          if old_contents == new_contents:
              # no change: avoid modifying the file modification time
              return
      except FileNotFoundError:
          pass
      # Atomic write using a temporary file and os.replace()
      filename_new = f"{filename}.new"
      with open(filename_new, "w", encoding="utf-8") as fp:
          fp.write(new_contents)
      try:
          os.replace(filename_new, filename)
      except:
          os.unlink(filename_new)
          raise
  
file_path: cpython/Tools/clinic/libclinic/utils.py
imports: import collections
  import hashlib
  import os
  import re
  import string
  from typing import Literal
label_desc: Use image node_id 1 for calling a global function with example usage: write_file(filename, new_contents) without return types