title: "Unsupported target for indexed assignment" with mypy, depending on type hinting moment with respect to assignment
body: <p>I'm trying to do some typing on my python code, and I got the following mypy error: "Unsupported target for indexed assignment"</p>
  
  <p>On a simplified example, it amounts to the following code:</p>
  
  <pre><code>from pathlib import Path
  from typing import (Literal, Mapping,
                      Optional, Union)
  
  STRAND = Literal["+", "-"]
  PATH = Union[str, Path]
  fastq_files: Mapping[STRAND, Optional[PATH]] = {  # simultaneous annotation and assignment
      "+": None,
      "-": None}
  
  reads_dir = Path("/tmp")
  fastq_files["+"] = reads_dir.joinpath(  # mypy error
      "plus.fastq.gz")
  fastq_files["-"] = reads_dir.joinpath(  # mypy error
      "minus.fastq.gz")
  </code></pre>
  
  <p>The error comes when replacing <code>None</code> with a <code>Path</code> in the dictionaries values.</p>
  
  <p>How come values supposed to be of type <code>Optional[PATH]</code> cannot be replaced with values of type <code>Path</code>, given that <code>PATH</code> is <code>Union[str, Path]</code>?
  I would have thought that a <code>Path</code> is compatible with <code>Union[str, Path]</code>, which in turn is compatible with <code>Optional[Union[str, Path]]</code>.</p>
  
  <p>And why does the error disappear when I annotate the dict before assignment instead of annotating it at assignment time (see below)?</p>
  
  <pre><code>from pathlib import Path
  from typing import (Literal, Mapping,
                      Optional, Union)
  
  STRAND = Literal["+", "-"]
  PATH = Union[str, Path]
  fastq_files: Mapping[STRAND, Optional[PATH]]  # annotation before assignment
  fastq_files = {
      "+": None,
      "-": None}
  
  reads_dir = Path("/tmp")
  fastq_files["+"] = reads_dir.joinpath(  # no mypy error
      "plus.fastq.gz")
  fastq_files["-"] = reads_dir.joinpath(  # no mypy error
      "minus.fastq.gz")
  </code></pre>
  
  <p>The above shows that a <code>None</code> can be replaced by a <code>Path</code> in a "slot" with type <code>Optional[Union[str, Path]]</code>.</p>
  
  <p>Does it mean that when I do the annotation at the same time as the assignment, the actual type is "reduced" to the strictest possible type compatible with the assigned value? (with the consequence that the "slot" gets a more restrictive type)</p>