original_docstring: Read an image file and return whether it is valid.
docstring: Read an image file and return whether it is valid.
docstring_tokens: Read an image file and return whether it is valid .
code: def is_valid_image(pth: Union[str, Path]) -> bool:
      """Read an image file and return whether it is valid."""
      from PIL import Image  # https://pypi.python.org/pypi/Pillow
      try:
          img = Image.open(str(pth))
      except IOError:
          return False
      try:
          img.load()
      except IOError:
          return False
      finally:
          if img.fp:
              img.fp.close()
      return True
code_tokens: def is_valid_image ( pth : Union [ str , Path ] ) -> bool : from PIL import Image try : img = Image . open ( str ( pth ) ) except IOError : return False try : img . load ( ) except IOError : return False finally : if img . fp : img . fp . close ( ) return True
short_docstring: Read an image file and return whether it is valid.
short_docstring_tokens: Read an image file and return whether it is valid .
comment: """Read an image file and return whether it is valid."""$SEP$# https://pypi.python.org/pypi/Pillow