title: mypy: define types for specific keys in dynamic dictionary
body: <p>I have the following dictionary representing a person that could be one of many variations. Here are just a few:</p>
  
  <pre><code>person = {"name": "Johnny"}
  person = {"name": "Johnny", "age": 25}
  person = {"name": "Johnny", "age": 25, "active": True}
  </code></pre>
  
  <p>I'm extracting certain keys and using them to print a statement. The problem arises in the type hints, where I'm getting an error saying <code>Incompatible types in assignment (expression has type "object", variable has type "Optional[str]")</code> when I run mypy on the script:</p>
  
  <pre><code>name: Optional[str] = person.get("name")  # mypy error here
  age: Optional[int] = person.get("age")    # mypy error here
  if name and age:
      print(f"In 5 years, {name} will be {age + 5} years old")
  </code></pre>
  
  <p>To solve this the <code>mypy_extensions.TypedDict</code> type seemed promising, but it appears I can't have missing or extra keys:</p>
  
  <pre><code>from mypy_extensions import TypedDict
  PersonDict = TypedDict("PersonDict", {"name": str, "age": int})
  
  # ERROR: Key 'age' missing for TypedDict "PersonDict"
  person: PersonDict = {"name": "Johnny"}
  
  # ERROR: Extra key 'active' for TypedDict "PersonDict"
  person: PersonDict = {"name": "Johnny", "age": 25, "active": True}
  </code></pre>
  
  <p>Is there anyway to define types for specific keys in a dictionary, even if the keys in that dictionary are dynamic?</p>