title: Interesting MYPY behavior - warning about difflib only once
body: <p>I have the following code:</p>
  
  <pre><code>"""
  FILE:
      diff_tool.py
  
  VERSION:
      .1 - initial file with arguments
      .2 - adding HTML output
  
  DESCRIPTION:
      script that shows the difference between two files.
  
      https://florian-dahlitz.de/blog/create-your-own-diff-tool-using-python
  """
  
  import difflib
  import sys
  import argparse
  
  from pathlib import Path
  from typing import Union, Iterator
  
  def create_diff(old_file: Path, new_file: Path, output_file: Path=None) -&gt; None:
      file_1 = open(old_file).readlines()
      file_2 = open(new_file).readlines()
  
      old_name: str = old_file.name
      new_name: str = new_file.name
      delta: Union[str, Iterator[str]] = ""
      if output_file:
          delta = difflib.HtmlDiff().make_file(
              file_1, file_2, old_name, new_name
          )
          with open(output_file, "w") as f:
              f.write(delta)
              f.close()
      else:
          delta = difflib.unified_diff(file_1, file_2, old_name, new_name)
          sys.stdout.writelines(delta)
  
  
  def main():
      parser = argparse.ArgumentParser()
      parser.add_argument("old_file_version")
      parser.add_argument("new_file_version")
      parser.add_argument("--html", help="specify html to write to")
      args = parser.parse_args()
  
      old_file = Path(args.old_file_version)
      new_file = Path(args.new_file_version)
  
      if args.html:
          output_file = Path(args.html)
      else:
          output_file = None
  
      create_diff(old_file, new_file, output_file)
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>I've commented after the else statement the mypy warning which is:</p>
  
  <pre><code>Incompatible types in assignment (expression has type "Iterator[str]", variable has type "str")
  </code></pre>
  
  <p>The issue is that the error doesn't show up twice. I know it has to do with the readlines in the file1 and file2 but why doesn't is occur when writing the diff work to an HTML file?</p>
  
  <p>UPDATE: 
  I've updated the code but thanks to Samwise defining delta as well cleared up the issue and everything works and no mypy errors. I'm definitely going to start really digging in on typing.</p>