code: def _write_if_changed(self, filename: str, contents: str) -> None:
      old_contents: Optional[str]
      try:
          with open(filename) as f:
              old_contents = f.read()
      except OSError:
          old_contents = None
      if contents != old_contents:
          # Create output directory if it doesn't exist
          os.makedirs(os.path.dirname(filename), exist_ok=True)
          with open(filename, "w") as f:
              f.write(contents)
  
imports: import contextlib
  import functools
  import hashlib
  import os
  import re
  import sys
  import textwrap
  from argparse import Namespace
  from dataclasses import fields, is_dataclass
  from enum import auto, Enum
  from typing import Any, Callable, Dict, Generic, Iterable, Iterator, List, Literal, NoReturn, Optional, Sequence, Set, Tuple, TypeVar, Union
  from typing_extensions import Self
  from torchgen.code_template import CodeTemplate
label_desc: Use image node_id 2 for calling the FileManager obj's underlying member method code with example usage: obj._write_if_changed(filename, contents) without return types