title: Best way to specify nested dict with pydantic?
body: <h2>Context</h2>
  <p>I'm trying to validate/parse some data with <code>pydantic</code>.</p>
  <p>I want to specify that the dict can have a key <code>daytime</code>, or not.
  If it does, I want the value of <code>daytime</code> to include both <code>sunrise</code> and <code>sunset</code>.</p>
  <p>e.g. These should be allowed:</p>
  <pre><code>{
     'type': 'solar',
     'daytime': {
        'sunrise': 4, # 4am
        'sunset': 18 # 6pm
     }
  }
  </code></pre>
  <p>And</p>
  <pre><code>{
     'type': 'wind'
     # daytime key is omitted
  }
  </code></pre>
  <p>And</p>
  <pre><code>{
     'type': 'wind',
     'daytime': None
  }
  </code></pre>
  <p>But I want to fail validation for</p>
  <pre><code>{
     'type': 'solar',
     'daytime': {
        'sunrise': 4
     }
  }
  </code></pre>
  <p>Because this has a <code>daytime</code> value, but no sunset value.</p>
  <h2>MWE</h2>
  <p>I've got some code that does this.
  If I run this script, it executes successfully.</p>
  <pre><code>from pydantic import BaseModel, ValidationError
  from typing import List, Optional, Dict
  
  class DayTime(BaseModel):
      sunrise: int
      sunset: int
      
  class Plant(BaseModel):
      daytime: Optional[DayTime] = None
      type: str
  
  p = Plant.parse_obj({'type': 'wind'})
  p = Plant.parse_obj({'type': 'wind', 'daytime': None})
  p = Plant.parse_obj({
      'type': 'solar', 
      'daytime': {
          'sunrise': 5, 
          'sunset': 18
      }})
      
  try:
      p = Plant.parse_obj({
          'type': 'solar', 
          'daytime': {
              'sunrise': 5
          }})
  except ValidationError:
      pass
  else:
      raise AssertionError(&quot;Should have failed&quot;)
  </code></pre>
  <h2>Question</h2>
  <p>What I'm wondering is,
  <strong>is this how you're supposed to use pydantic for nested data?</strong></p>
  <p>I have lots of layers of nesting, and this seems a bit verbose.</p>
  <p>Is there any way to do something more concise, like:</p>
  <pre><code>class Plant(BaseModel):
      daytime: Optional[Dict[('sunrise', 'sunset'), int]] = None
      type: str
  </code></pre>