title: How to annotate optional dict keys with Python 3.9 standard annotations?
body: <p>I'm trying to understand how to use Python 3.9 type hint to annotate a function that receives a dict with optional or multiple type values. I know that with Typing module, I can use easily <code>Union</code> and <code>Optional</code>. But I'd like to know if it is possible to achieve that using only Python 3.9 annotations. I didn't found anything on this matter on <a href="https://www.python.org/dev/peps/pep-0585/" rel="nofollow noreferrer">PEP 585</a>.</p>
  <p>Reference: <a href="https://stackoverflow.com/questions/51710037/how-should-i-use-the-optional-type-hint">How should I use the Optional type hint?</a></p>
  <p>Example:</p>
  <pre><code>From Typing import Dict, Optional, Union
  
  def foo(bar: Dict[Union[str, int], Optional[str]]) -&gt; bool: return True
  </code></pre>
  <p>Should I do instead:</p>
  <pre><code>from __future__ import annotations
  
  def foo(bar: dict[[str, int], [str, None]) -&gt; bool: return True
  </code></pre>